def finalize(node_tree, material): """Finalize node tree and material settings. Should be called as last. :param node_tree: node tree on which this shader should be finalized :type node_tree: bpy.types.NodeTree :param material: material used for this shader :type material: bpy.types.Material """ material.use_backface_culling = True material.blend_method = "OPAQUE" # set proper blend method if alpha_test.is_set(node_tree): material.blend_method = "CLIP" material.alpha_threshold = 0.05 # add alpha test pass if multiply blend enabled, where alphed pixels shouldn't be multiplied as they are discarded if blend_mult.is_set(node_tree): lum_out_shader_n = node_tree.nodes[ DifLumSpec.LUM_OUT_SHADER_NODE] # alpha test pass has to get fully opaque input, thus remove transparency linkage compose_lighting_n = node_tree.nodes[ DifSpec.COMPOSE_LIGHTING_NODE] if compose_lighting_n.inputs['Alpha'].links: node_tree.links.remove( compose_lighting_n.inputs['Alpha'].links[0]) if lum_out_shader_n.inputs['Transparency'].links: node_tree.links.remove( lum_out_shader_n.inputs['Transparency'].links[0]) shader_from = lum_out_shader_n.outputs['BSDF'] alpha_from = node_tree.nodes[DifSpec.OPACITY_NODE].outputs[0] shader_to = lum_out_shader_n.outputs['BSDF'].links[0].to_socket alpha_test.add_pass(node_tree, shader_from, alpha_from, shader_to) if blend_add.is_set(node_tree): material.blend_method = "BLEND" if blend_mult.is_set(node_tree): material.blend_method = "BLEND" if blend_over.is_set(node_tree): material.blend_method = "BLEND"
def set_blend_add_flavor(node_tree, switch_on): """Set blend add flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend add should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): DifSpecMultDifSpec.set_alpha_test_flavor(node_tree, False) out_node = node_tree.nodes[DifSpecMultDifSpec.OUT_MAT_NODE] in_node = node_tree.nodes[DifSpecMultDifSpec.VCOL_GROUP_NODE] if switch_on: blend_add.init(node_tree, in_node.outputs['Vertex Color Alpha'], out_node.inputs['Alpha']) else: blend_add.delete(node_tree)
def set_blend_add_flavor(node_tree, switch_on): """Set blend add flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend add should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitTex.set_alpha_test_flavor(node_tree, False) if switch_on: out_node = node_tree.nodes[UnlitTex.OUTPUT_NODE] in_node = node_tree.nodes[UnlitTex.BASE_TEX_NODE] blend_add.init(node_tree, in_node.outputs['Value'], out_node.inputs['Alpha']) else: blend_add.delete(node_tree)
def set_blend_add_flavor(node_tree, switch_on): """Set blend add flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend add should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): Dif.set_alpha_test_flavor(node_tree, False) out_node = node_tree.nodes[Dif.OUT_MAT_NODE] in_node = node_tree.nodes[Dif.BASE_TEX_NODE] if switch_on: blend_add.init(node_tree, in_node.outputs['Value'], out_node.inputs['Alpha']) else: blend_add.delete(node_tree)
def set_blend_over_flavor(node_tree, switch_on): """Set blend over flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend over should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): DifSpecWeightWeightDifSpecWeight.set_alpha_test_flavor(node_tree, False) out_node = node_tree.nodes[DifSpec.OUT_MAT_NODE] in_node = node_tree.nodes[DifSpec.VCOL_GROUP_NODE] if switch_on: blend_over.init(node_tree, in_node.outputs['Vertex Color Alpha'], out_node.inputs['Alpha']) else: blend_over.delete(node_tree)
def set_blend_over_flavor(node_tree, switch_on): """Set blend over flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend over should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): Dif.set_alpha_test_flavor(node_tree, False) out_node = node_tree.nodes[Dif.OUT_MAT_NODE] in_node = node_tree.nodes[Dif.OPACITY_NODE] if switch_on: blend_over.init(node_tree, in_node.outputs['Value'], out_node.inputs['Alpha']) else: blend_over.delete(node_tree)
def set_awhite_flavor(node_tree, switch_on): """Set alpha white flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if alpha white flavor should be switched on or off :type switch_on: bool """ output_n = node_tree.nodes[UnlitVcolTex.OUTPUT_NODE] from_mix_factor = node_tree.nodes[UnlitVcolTex.OPACITY_NODE].outputs[0] from_color_socket = node_tree.nodes[ UnlitVcolTex.TEX_MULT_NODE].outputs['Color'] # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitVcolTex.set_alpha_test_flavor(node_tree, False) if switch_on: is_blend_mult_set = blend_mult.is_set(node_tree) # disable blend mult first if is_blend_mult_set: UnlitVcolTex.set_blend_mult_flavor(node_tree, False) location = (output_n.location.x - 185, output_n.location.y - 100) output_n.location.x += 185 awhite.init(node_tree, location, from_mix_factor, from_color_socket, output_n.inputs['Color']) # re-enable blend mult again if is_blend_mult_set: UnlitVcolTex.set_blend_mult_flavor(node_tree, True) else: output_n.location.x -= 185 awhite.delete(node_tree) node_tree.links.new(output_n.inputs['Color'], from_color_socket)
def set_blend_over_flavor(node_tree, switch_on): """Set blend over flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend over should be switched on or off :type switch_on: bool """ # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitVcolTex.set_alpha_test_flavor(node_tree, False) if switch_on: out_node = node_tree.nodes[UnlitVcolTex.OUTPUT_NODE] in_node = node_tree.nodes[UnlitVcolTex.OPACITY_NODE] blend_over.init(node_tree, in_node.outputs['Value'], out_node.inputs['Alpha']) else: blend_over.delete(node_tree)
def set_blend_mult_flavor(node_tree, switch_on): """Set mult blending flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend mult should be switched on or off :type switch_on: bool """ output_n = node_tree.nodes[UnlitVcolTex.OUTPUT_NODE] from_color_socket = awhite.get_out_socket(node_tree) if not from_color_socket: from_color_socket = node_tree.nodes[ UnlitVcolTex.TEX_MULT_NODE].outputs['Color'] to_color_socket = output_n.inputs['Color'] from_alpha_socket = node_tree.nodes[ UnlitVcolTex.OPACITY_NODE].outputs[0] to_alpha_socket = output_n.inputs['Alpha'] # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitVcolTex.set_alpha_test_flavor(node_tree, False) if switch_on: location = (output_n.location.x - 185, output_n.location.y) output_n.location.x += 185 blend_mult.init(node_tree, location, from_alpha_socket, to_alpha_socket, from_color_socket, to_color_socket) else: output_n.location.x -= 185 blend_mult.delete(node_tree) # make sure to reaply awhite if set UnlitVcolTex.set_awhite_flavor(node_tree, awhite.is_set(node_tree))
def finalize(node_tree, material): """Set output material for this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param material: blender material for used in this tree node as output :type material: bpy.types.Material """ material.use_backface_culling = True material.blend_method = "OPAQUE" # set proper blend method if alpha_test.is_set(node_tree): material.blend_method = "CLIP" material.alpha_threshold = 0.05 # add alpha test pass if multiply blend enabled, where alphed pixels shouldn't be multiplied as they are discarded if blend_mult.is_set(node_tree): out_shader_n = node_tree.nodes[UnlitTex.OUT_SHADER_NODE] # alpha test pass has to get fully opaque input, thus remove transparency linkage if out_shader_n.inputs['Transparency'].links: node_tree.links.remove( out_shader_n.inputs['Transparency'].links[0]) shader_from = out_shader_n.outputs['BSDF'] alpha_from = node_tree.nodes[ UnlitTex.BASE_TEX_NODE].outputs['Alpha'] shader_to = out_shader_n.outputs['BSDF'].links[0].to_socket alpha_test.add_pass(node_tree, shader_from, alpha_from, shader_to) if blend_add.is_set(node_tree): material.blend_method = "BLEND" if blend_mult.is_set(node_tree): material.blend_method = "BLEND" if blend_over.is_set(node_tree): material.blend_method = "BLEND"
def set_awhite_flavor(node_tree, switch_on): """Set alpha white flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if alpha white flavor should be switched on or off :type switch_on: bool """ output_n = node_tree.nodes[UnlitVcolTex.OUTPUT_NODE] from_mix_factor = node_tree.nodes[UnlitVcolTex.OPACITY_NODE].outputs[0] from_color_socket = node_tree.nodes[UnlitVcolTex.TEX_MULT_NODE].outputs["Color"] # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitVcolTex.set_alpha_test_flavor(node_tree, False) if switch_on: is_blend_mult_set = blend_mult.is_set(node_tree) # disable blend mult first if is_blend_mult_set: UnlitVcolTex.set_blend_mult_flavor(node_tree, False) location = (output_n.location.x - 185, output_n.location.y - 100) output_n.location.x += 185 awhite.init(node_tree, location, from_mix_factor, from_color_socket, output_n.inputs["Color"]) # re-enable blend mult again if is_blend_mult_set: UnlitVcolTex.set_blend_mult_flavor(node_tree, True) else: output_n.location.x -= 185 awhite.delete(node_tree) node_tree.links.new(output_n.inputs["Color"], from_color_socket)
def finalize(node_tree, material): """Finalize node tree and material settings. Should be called as last. :param node_tree: node tree on which this shader should be finalized :type node_tree: bpy.types.NodeTree :param material: material used for this shader :type material: bpy.types.Material """ material.use_backface_culling = True material.blend_method = "OPAQUE" # set proper blend method if alpha_test.is_set(node_tree): material.blend_method = "CLIP" material.alpha_threshold = 0.05 # add alpha test pass if: # 1. awhite is enabled, as alpha test pass is called before awhite is aplied # 2. multiply blend enabled, where alphed pixels shouldn't be multiplied as they are discarded if awhite.is_set(node_tree) or blend_mult.is_set(node_tree): out_shader_n = node_tree.nodes[UnlitVcolTex.OUT_SHADER_NODE] # alpha test pass has to get fully opaque input, thus remove transparency linkage if out_shader_n.inputs['Transparency'].links: node_tree.links.remove(out_shader_n.inputs['Transparency'].links[0]) shader_from = out_shader_n.outputs['BSDF'] alpha_from = node_tree.nodes[UnlitVcolTex.OPACITY_NODE].outputs[0] shader_to = out_shader_n.outputs['BSDF'].links[0].to_socket alpha_test.add_pass(node_tree, shader_from, alpha_from, shader_to) if blend_add.is_set(node_tree): material.blend_method = "BLEND" if blend_mult.is_set(node_tree): material.blend_method = "BLEND" if blend_over.is_set(node_tree): material.blend_method = "BLEND"
def set_blend_mult_flavor(node_tree, switch_on): """Set mult blending flavor to this shader. :param node_tree: node tree of current shader :type node_tree: bpy.types.NodeTree :param switch_on: flag indication if blend mult should be switched on or off :type switch_on: bool """ output_n = node_tree.nodes[UnlitVcolTex.OUTPUT_NODE] from_color_socket = awhite.get_out_socket(node_tree) if not from_color_socket: from_color_socket = node_tree.nodes[UnlitVcolTex.TEX_MULT_NODE].outputs["Color"] to_color_socket = output_n.inputs["Color"] from_alpha_socket = node_tree.nodes[UnlitVcolTex.OPACITY_NODE].outputs[0] to_alpha_socket = output_n.inputs["Alpha"] # remove alpha test flavor if it was set already. Because these two can not coexist if alpha_test.is_set(node_tree): UnlitVcolTex.set_alpha_test_flavor(node_tree, False) if switch_on: location = (output_n.location.x - 185, output_n.location.y) output_n.location.x += 185 blend_mult.init(node_tree, location, from_alpha_socket, to_alpha_socket, from_color_socket, to_color_socket) else: output_n.location.x -= 185 blend_mult.delete(node_tree) # make sure to reaply awhite if set UnlitVcolTex.set_awhite_flavor(node_tree, awhite.is_set(node_tree))