Exemplo n.º 1
0
    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"
Exemplo n.º 2
0
    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"
Exemplo n.º 3
0
    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"
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)