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:
@@ -192,17 +192,6 @@ class QuickExplode(Operator):
|
|||||||
|
|
||||||
return {'CANCELLED'}
|
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':
|
if self.style == 'BLEND':
|
||||||
from_obj = mesh_objects[1]
|
from_obj = mesh_objects[1]
|
||||||
to_obj = mesh_objects[0]
|
to_obj = mesh_objects[0]
|
||||||
@@ -229,30 +218,59 @@ class QuickExplode(Operator):
|
|||||||
explode.particle_uv = uv.name
|
explode.particle_uv = uv.name
|
||||||
|
|
||||||
mat = object_ensure_material(obj, "Explode Fade")
|
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
|
nodes = mat.node_tree.nodes
|
||||||
mat.use_transparent_shadows = True
|
for node in nodes:
|
||||||
mat.alpha = 0.0
|
if (node.type == 'OUTPUT_MATERIAL'):
|
||||||
mat.specular_alpha = 0.0
|
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
|
node_x = node_surface.location[0]
|
||||||
tex_slot.texture_coords = 'UV'
|
node_y = node_surface.location[1] - 400
|
||||||
tex_slot.uv_layer = uv.name
|
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':
|
if self.style == 'BLEND':
|
||||||
|
color_ramp.elements[0].position = 0.333
|
||||||
|
color_ramp.elements[1].position = 0.666
|
||||||
if obj == to_obj:
|
if obj == to_obj:
|
||||||
tex_slot.alpha_factor = -1.0
|
# reverse ramp alpha
|
||||||
elem = tex.color_ramp.elements[1]
|
color_ramp.elements[0].color[3] = 1.0
|
||||||
else:
|
color_ramp.elements[1].color[3] = 0.0
|
||||||
elem = tex.color_ramp.elements[0]
|
|
||||||
# Keep already defined alpha!
|
node_sep = nodes.new('ShaderNodeSeparateXYZ')
|
||||||
elem.color[:3] = mat.diffuse_color
|
node_sep.location = (node_x - offset_x, node_y)
|
||||||
else:
|
offset_x += 200
|
||||||
tex_slot.use_map_color_diffuse = False
|
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':
|
if self.style == 'BLEND':
|
||||||
settings.physics_type = 'KEYED'
|
settings.physics_type = 'KEYED'
|
||||||
|
Reference in New Issue
Block a user