From 54985ab5f569f4623695c693dedda7c000e1e73f Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Mon, 7 Jan 2019 15:42:46 +0100 Subject: 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 --- .../startup/bl_operators/object_quick_effects.py | 82 +++++++++++++--------- 1 file changed, 50 insertions(+), 32 deletions(-) (limited to 'release') diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py index a47bdf9ff32..37c4af593c5 100644 --- a/release/scripts/startup/bl_operators/object_quick_effects.py +++ b/release/scripts/startup/bl_operators/object_quick_effects.py @@ -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.use_transparency = True - mat.use_transparent_shadows = True - mat.alpha = 0.0 - mat.specular_alpha = 0.0 - - tex_slot = mat.texture_slots.add() - - tex_slot.texture = tex - tex_slot.texture_coords = 'UV' - tex_slot.uv_layer = uv.name - - tex_slot.use_map_alpha = True + mat.blend_method = 'BLEND' + mat.transparent_shadow_method = 'HASHED' + if not mat.use_nodes: + mat.use_nodes = True + + nodes = mat.node_tree.nodes + for node in nodes: + if (node.type == 'OUTPUT_MATERIAL'): + node_out_mat = node + break + + node_surface = node_out_mat.inputs['Surface'].links[0].from_node + + node_x = node_surface.location[0] + node_y = node_surface.location[1] - 400 + offset_x = 200 + + 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' -- cgit v1.2.3