Quick Explode: replace BI based material handling (using 'fade'/'blend')
using a simple shader graph mixing Transparent BSDF now Fixes T59185 Reviewers: brecht Maniphest Tasks: T59185 Differential Revision: https://developer.blender.org/D4181
This commit is contained in:
parent
4b55945da6
commit
54985ab5f5
Notes:
blender-bot
2023-02-14 04:33:25 +01:00
Referenced by issue #59185, Quick Explode is broken in 2.8
|
@ -192,17 +192,6 @@ class QuickExplode(Operator):
|
|||
|
||||
return {'CANCELLED'}
|
||||
|
||||
if self.fade:
|
||||
tex = bpy.data.textures.new("Explode fade", 'BLEND')
|
||||
tex.use_color_ramp = True
|
||||
|
||||
if self.style == 'BLEND':
|
||||
tex.color_ramp.elements[0].position = 0.333
|
||||
tex.color_ramp.elements[1].position = 0.666
|
||||
|
||||
tex.color_ramp.elements[0].color[3] = 1.0
|
||||
tex.color_ramp.elements[1].color[3] = 0.0
|
||||
|
||||
if self.style == 'BLEND':
|
||||
from_obj = mesh_objects[1]
|
||||
to_obj = mesh_objects[0]
|
||||
|
@ -229,30 +218,59 @@ class QuickExplode(Operator):
|
|||
explode.particle_uv = uv.name
|
||||
|
||||
mat = object_ensure_material(obj, "Explode Fade")
|
||||
mat.blend_method = 'BLEND'
|
||||
mat.transparent_shadow_method = 'HASHED'
|
||||
if not mat.use_nodes:
|
||||
mat.use_nodes = True
|
||||
|
||||
mat.use_transparency = True
|
||||
mat.use_transparent_shadows = True
|
||||
mat.alpha = 0.0
|
||||
mat.specular_alpha = 0.0
|
||||
nodes = mat.node_tree.nodes
|
||||
for node in nodes:
|
||||
if (node.type == 'OUTPUT_MATERIAL'):
|
||||
node_out_mat = node
|
||||
break
|
||||
|
||||
tex_slot = mat.texture_slots.add()
|
||||
node_surface = node_out_mat.inputs['Surface'].links[0].from_node
|
||||
|
||||
tex_slot.texture = tex
|
||||
tex_slot.texture_coords = 'UV'
|
||||
tex_slot.uv_layer = uv.name
|
||||
node_x = node_surface.location[0]
|
||||
node_y = node_surface.location[1] - 400
|
||||
offset_x = 200
|
||||
|
||||
tex_slot.use_map_alpha = True
|
||||
node_mix = nodes.new('ShaderNodeMixShader')
|
||||
node_mix.location = (node_x - offset_x, node_y)
|
||||
mat.node_tree.links.new(node_surface.outputs["BSDF"], node_mix.inputs[1])
|
||||
mat.node_tree.links.new(node_mix.outputs["Shader"], node_out_mat.inputs['Surface'])
|
||||
offset_x += 200
|
||||
|
||||
node_trans = nodes.new('ShaderNodeBsdfTransparent')
|
||||
node_trans.location = (node_x - offset_x, node_y)
|
||||
mat.node_tree.links.new(node_trans.outputs["BSDF"], node_mix.inputs[2])
|
||||
offset_x += 200
|
||||
|
||||
node_ramp = nodes.new('ShaderNodeValToRGB')
|
||||
node_ramp.location = (node_x - offset_x, node_y)
|
||||
offset_x += 200
|
||||
mat.node_tree.links.new(node_ramp.outputs["Alpha"], node_mix.inputs["Fac"])
|
||||
color_ramp = node_ramp.color_ramp
|
||||
color_ramp.elements[0].color[3] = 0.0
|
||||
color_ramp.elements[1].color[3] = 1.0
|
||||
|
||||
if self.style == 'BLEND':
|
||||
color_ramp.elements[0].position = 0.333
|
||||
color_ramp.elements[1].position = 0.666
|
||||
if obj == to_obj:
|
||||
tex_slot.alpha_factor = -1.0
|
||||
elem = tex.color_ramp.elements[1]
|
||||
else:
|
||||
elem = tex.color_ramp.elements[0]
|
||||
# Keep already defined alpha!
|
||||
elem.color[:3] = mat.diffuse_color
|
||||
else:
|
||||
tex_slot.use_map_color_diffuse = False
|
||||
# reverse ramp alpha
|
||||
color_ramp.elements[0].color[3] = 1.0
|
||||
color_ramp.elements[1].color[3] = 0.0
|
||||
|
||||
node_sep = nodes.new('ShaderNodeSeparateXYZ')
|
||||
node_sep.location = (node_x - offset_x, node_y)
|
||||
offset_x += 200
|
||||
mat.node_tree.links.new(node_sep.outputs["X"], node_ramp.inputs["Fac"])
|
||||
|
||||
node_uv = nodes.new('ShaderNodeUVMap')
|
||||
node_uv.location = (node_x - offset_x, node_y)
|
||||
node_uv.uv_map = uv.name
|
||||
mat.node_tree.links.new(node_uv.outputs["UV"], node_sep.inputs["Vector"])
|
||||
|
||||
if self.style == 'BLEND':
|
||||
settings.physics_type = 'KEYED'
|
||||
|
|
Loading…
Reference in New Issue