Ejemplo n.º 1
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        # init parent
        Dif.init(node_tree)

        geom_n = node_tree.nodes[Dif.GEOM_NODE]
        lighting_eval_n = node_tree.nodes[Dif.LIGHTING_EVAL_NODE]

        # nodes creation
        normal_trans_n = node_tree.nodes.new("ShaderNodeVectorTransform")
        normal_trans_n.name = normal_trans_n.label = Grass.NORMAL_TRANS_NODE
        normal_trans_n.location = (geom_n.location.x, geom_n.location.y - 250)
        normal_trans_n.vector_type = "NORMAL"
        normal_trans_n.convert_from = "OBJECT"
        normal_trans_n.convert_to = "WORLD"
        normal_trans_n.inputs['Vector'].default_value = (
            0, 0, 1)  # up normal in object space

        # links creation
        node_tree.links.new(lighting_eval_n.inputs['Normal Vector'],
                            normal_trans_n.outputs['Vector'])

        # enable hardcoded flavour
        Dif.set_alpha_test_flavor(node_tree, True)
Ejemplo n.º 2
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = DifSpec.SPEC_MULT_NODE
        spec_mult_n.label = DifSpec.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1900)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        # links creation
        node_tree.links.new(spec_mult_n.inputs['Color2'], base_tex_n.outputs['Value'])
        node_tree.links.new(spec_mult_n.inputs['Color1'], spec_col_n.outputs['Color'])

        node_tree.links.new(out_mat_n.inputs['Spec'], spec_mult_n.outputs['Color'])
Ejemplo n.º 3
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        output_n = node_tree.nodes[Dif.OUTPUT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]
        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]

        # move existing
        output_n.location.x += pos_x_shift

        # nodes creation
        lum_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        lum_mix_n.name = DifLum.LUM_MIX_NODE
        lum_mix_n.label = DifLum.LUM_MIX_NODE
        lum_mix_n.location = (out_mat_n.location.x + pos_x_shift, out_mat_n.location.y + 200)
        lum_mix_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(lum_mix_n.inputs['Fac'], base_tex_n.outputs['Value'])
        node_tree.links.new(lum_mix_n.inputs['Color1'], out_mat_n.outputs['Color'])
        node_tree.links.new(lum_mix_n.inputs['Color2'], base_tex_n.outputs['Color'])

        node_tree.links.new(output_n.inputs['Color'], lum_mix_n.outputs['Color'])
Ejemplo n.º 4
0
    def set_material(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
        """

        Dif.set_material(node_tree, material)

        material.use_transparency = True
Ejemplo n.º 5
0
    def init(node_tree, disable_remap_alpha=False):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        :param disable_remap_alpha: shoudl alpha remaping with weight factors (used for alpha test safe weighting) be disabled?
        :type disable_remap_alpha: bool
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeVectorMath")
        spec_mult_n.name = DifSpec.SPEC_MULT_NODE
        spec_mult_n.label = DifSpec.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 3,
                                start_pos_y + 1900)
        spec_mult_n.operation = "MULTIPLY"

        remap_alpha_n = None
        if not disable_remap_alpha:
            remap_alpha_n = node_tree.nodes.new("ShaderNodeGroup")
            remap_alpha_n.name = remap_alpha_n.label = DifSpec.REMAP_ALPHA_GNODE
            remap_alpha_n.location = (start_pos_x + pos_x_shift * 2,
                                      start_pos_y + 1900)
            remap_alpha_n.node_tree = alpha_remap_ng.get_node_group()
            remap_alpha_n.inputs['Factor1'].default_value = 1.0
            remap_alpha_n.inputs['Factor2'].default_value = 0.0

        # links creation
        if not disable_remap_alpha:
            node_tree.links.new(remap_alpha_n.inputs['Alpha'],
                                base_tex_n.outputs['Alpha'])
            node_tree.links.new(spec_mult_n.inputs[1],
                                remap_alpha_n.outputs['Weighted Alpha'])
        else:
            node_tree.links.new(spec_mult_n.inputs[1],
                                base_tex_n.outputs['Alpha'])

        node_tree.links.new(spec_mult_n.inputs[0], spec_col_n.outputs['Color'])

        node_tree.links.new(compose_lighting_n.inputs['Specular Color'],
                            spec_mult_n.outputs[0])
Ejemplo n.º 6
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
        """
        Dif.finalize(node_tree, material)

        # in game it gets added to framebuffer, however we don't have access to frame buffer thus make approximation with alpha blending
        material.blend_method = "BLEND"
Ejemplo n.º 7
0
    def set_material(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
        """

        # set hardcoded shininness
        material.specular_hardness = 60

        Dif.set_material(node_tree, material)
Ejemplo n.º 8
0
    def set_material(node_tree, material):
        """Set output material for this shader.
        NOTE: extended to ensure transparency for this shader, which gives
        partial look of multiplying with underlying surfaces.

        :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
        """
        Dif.set_material(node_tree, material)

        material.use_transparency = True
Ejemplo n.º 9
0
    def set_material(node_tree, material):
        """Set output material for this shader.
        NOTE: extended to ensure transparency for this shader, which gives
        partial look of multiplying with underlying surfaces.

        :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
        """
        Dif.set_material(node_tree, material)

        material.use_transparency = True
Ejemplo n.º 10
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        NOTE: there is no visualization of extra light boost from player

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        # init parent
        Dif.init(node_tree)

        # enable hardcoded flavors
        Dif.set_blend_over_flavor(node_tree, True)
Ejemplo n.º 11
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.LIGHTING_EVAL_NODE])

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        v_col_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]
        compose_lighting_n.inputs['Diffuse Lighting'].default_value = (
            1.0, ) * 4
        compose_lighting_n.inputs['Specular Lighting'].default_value = (
            1.0, ) * 4

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeVectorMath")
        spec_mult_n.name = LightTex.SPEC_MULT_NODE
        spec_mult_n.label = LightTex.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 5,
                                start_pos_y + 1850)
        spec_mult_n.operation = "MULTIPLY"

        rgb_to_bw_n = node_tree.nodes.new("ShaderNodeRGBToBW")
        rgb_to_bw_n.name = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.label = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.location = (start_pos_x + pos_x_shift * 3,
                                start_pos_y + 1300)

        # links creation
        node_tree.links.new(spec_mult_n.inputs[0], v_col_mult_n.outputs[0])
        node_tree.links.new(compose_lighting_n.inputs["Specular Color"],
                            spec_mult_n.outputs[0])

        node_tree.links.new(rgb_to_bw_n.inputs["Color"],
                            base_tex_n.outputs["Color"])
        node_tree.links.new(compose_lighting_n.inputs["Alpha"],
                            rgb_to_bw_n.outputs["Val"])
Ejemplo n.º 12
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        # init parent
        Dif.init(node_tree)

        out_mat_n = node_tree.nodes[Dif.OUTPUT_NODE]
        opacity_n = node_tree.nodes[Dif.OPACITY_NODE]

        # create links
        node_tree.links.new(out_mat_n.inputs['Alpha'], opacity_n.outputs[0])
Ejemplo n.º 13
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        v_col_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = LightTex.SPEC_MULT_NODE
        spec_mult_n.label = LightTex.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 5,
                                start_pos_y + 1850)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        rgb_to_bw_n = node_tree.nodes.new("ShaderNodeRGBToBW")
        rgb_to_bw_n.name = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.label = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.location = (start_pos_x + pos_x_shift * 3,
                                start_pos_y + 1300)

        # links creation
        node_tree.links.new(spec_mult_n.inputs["Color1"],
                            v_col_mult_n.outputs["Color"])
        node_tree.links.new(out_mat_n.inputs["Spec"],
                            spec_mult_n.outputs["Color"])

        node_tree.links.new(rgb_to_bw_n.inputs["Color"],
                            base_tex_n.outputs["Color"])
        node_tree.links.new(out_mat_n.inputs["Alpha"],
                            rgb_to_bw_n.outputs["Val"])
Ejemplo n.º 14
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        opacity_n = node_tree.nodes[Dif.OPACITY_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.SPEC_COL_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.DIFF_COL_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.DIFF_MULT_NODE])

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeMath")
        spec_mult_n.name = Retroreflective.SPEC_MULT_NODE
        spec_mult_n.label = Retroreflective.SPEC_MULT_NODE
        spec_mult_n.location = (opacity_n.location[0] + pos_x_shift,
                                opacity_n.location[1])
        spec_mult_n.operation = "MULTIPLY"
        spec_mult_n.inputs[
            1].default_value = 0.2  # used for spcular color designed for the best visual on traffic signs

        # links creation
        node_tree.links.new(spec_mult_n.inputs[0], opacity_n.outputs['Value'])

        node_tree.links.new(compose_lighting_n.inputs['Diffuse Color'],
                            vcol_mult_n.outputs['Color'])
        node_tree.links.new(out_mat_n.inputs['Color'],
                            vcol_mult_n.outputs['Color'])

        node_tree.links.new(out_mat_n.inputs['Spec'],
                            spec_mult_n.outputs['Value'])
Ejemplo n.º 15
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = DifSpec.SPEC_MULT_NODE
        spec_mult_n.label = DifSpec.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1900)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        spec_scale_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_scale_n.name = DifSpec.SPEC_SCALE_NODE
        spec_scale_n.label = DifSpec.SPEC_SCALE_NODE
        spec_scale_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 1900)
        spec_scale_n.blend_type = "MULTIPLY"
        spec_scale_n.inputs['Fac'].default_value = 2
        spec_scale_n.inputs['Color2'].default_value = (2,) * 4

        # links creation
        node_tree.links.new(spec_mult_n.inputs['Color2'], base_tex_n.outputs['Value'])
        node_tree.links.new(spec_mult_n.inputs['Color1'], spec_col_n.outputs['Color'])

        node_tree.links.new(spec_scale_n.inputs['Color1'], spec_mult_n.outputs['Color'])

        node_tree.links.new(out_mat_n.inputs['Spec'], spec_scale_n.outputs['Color'])
Ejemplo n.º 16
0
    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.OPACITY_NODE]

        if switch_on:
            blend_add.init(node_tree, in_node.outputs['Color'], out_node.inputs['Alpha'])
        else:
            blend_add.delete(node_tree)
Ejemplo n.º 17
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        v_col_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # node creation
        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = LightTex.SPEC_MULT_NODE
        spec_mult_n.label = LightTex.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 5, start_pos_y + 1850)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        rgb_to_bw_n = node_tree.nodes.new("ShaderNodeRGBToBW")
        rgb_to_bw_n.name = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.label = LightTex.RGB_TO_BW_ALPHA_NODE
        rgb_to_bw_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1300)

        # links creation
        node_tree.links.new(spec_mult_n.inputs["Color1"], v_col_mult_n.outputs["Color"])
        node_tree.links.new(out_mat_n.inputs["Spec"], spec_mult_n.outputs["Color"])

        node_tree.links.new(rgb_to_bw_n.inputs["Color"], base_tex_n.outputs["Color"])
        node_tree.links.new(out_mat_n.inputs["Alpha"], rgb_to_bw_n.outputs["Val"])
Ejemplo n.º 18
0
    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.OPACITY_NODE]

        if switch_on:
            blend_add.init(node_tree, in_node.outputs['Color'],
                           out_node.inputs['Alpha'])
        else:
            blend_add.delete(node_tree)
Ejemplo n.º 19
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        vcol_group_n = node_tree.nodes[Dif.VCOL_GROUP_NODE]
        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        # node creation
        sec_geom_n = node_tree.nodes.new("ShaderNodeGeometry")
        sec_geom_n.name = sec_geom_n.label = DifWeightDif.SEC_GEOM_NODE
        sec_geom_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1200)
        sec_geom_n.uv_layer = _MESH_consts.none_uv

        over_tex_n = node_tree.nodes.new("ShaderNodeTexture")
        over_tex_n.name = over_tex_n.label = DifWeightDif.OVER_TEX_NODE
        over_tex_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1200)

        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = spec_mult_n.label = DifWeightDif.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 1900)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        base_over_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_over_mix_n.name = base_over_mix_n.label = DifWeightDif.BASE_OVER_MIX_NODE
        base_over_mix_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1300)
        base_over_mix_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(over_tex_n.inputs['Vector'], sec_geom_n.outputs['UV'])

        # pass 1
        node_tree.links.new(base_over_mix_n.inputs['Fac'], vcol_group_n.outputs['Vertex Color Alpha'])
        node_tree.links.new(base_over_mix_n.inputs['Color1'], base_tex_n.outputs['Color'])
        node_tree.links.new(base_over_mix_n.inputs['Color2'], over_tex_n.outputs['Color'])

        # pass 2
        node_tree.links.new(spec_mult_n.inputs['Color1'], spec_col_n.outputs['Color'])
        node_tree.links.new(spec_mult_n.inputs['Color2'], vcol_group_n.outputs['Vertex Color'])

        node_tree.links.new(vcol_mult_n.inputs['Color2'], base_over_mix_n.outputs['Color'])

        # pass to material
        node_tree.links.new(out_mat_n.inputs['Spec'], spec_mult_n.outputs['Color'])
Ejemplo n.º 20
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        geom_n = node_tree.nodes[Dif.GEOM_NODE]
        diff_col_n = node_tree.nodes[Dif.DIFF_COL_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        lighting_eval_n = node_tree.nodes[Dif.LIGHTING_EVAL_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]
        output_n = node_tree.nodes[Dif.OUTPUT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.BASE_TEX_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.DIFF_MULT_NODE])

        # move existing
        vcol_mult_n.location.y -= 0
        lighting_eval_n.location.x += pos_x_shift * 3
        compose_lighting_n.location.x += pos_x_shift * 3
        output_n.location.x += pos_x_shift * 3

        # nodes creation
        water_stream_n = node_tree.nodes.new("ShaderNodeGroup")
        water_stream_n.name = water_stream_n.label = Water.WATER_STREAM_NODE
        water_stream_n.location = (start_pos_x - pos_x_shift,
                                   start_pos_y + 700)
        water_stream_n.node_tree = water_stream_ng.get_node_group()

        mix_factor_n = node_tree.nodes.new("ShaderNodeGroup")
        mix_factor_n.name = mix_factor_n.label = Water.MIX_FACTOR_GNODE
        mix_factor_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1500)
        mix_factor_n.node_tree = mix_factor_ng.get_node_group()

        near_col_n = node_tree.nodes.new("ShaderNodeRGB")
        near_col_n.label = near_col_n.name = Water.NEAR_COLOR_NODE
        near_col_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1300)

        horizon_col_n = node_tree.nodes.new("ShaderNodeRGB")
        horizon_col_n.label = horizon_col_n.name = Water.HORIZON_COLOR_NODE
        horizon_col_n.location = (start_pos_x + pos_x_shift,
                                  start_pos_y + 1100)

        near_mix_n = node_tree.nodes.new("ShaderNodeVectorMath")
        near_mix_n.name = near_mix_n.label = Water.NEAR_MIX_NODE
        near_mix_n.location = (start_pos_x + pos_x_shift * 5,
                               start_pos_y + 1400)
        near_mix_n.operation = "MULTIPLY"

        horizon_mix_n = node_tree.nodes.new("ShaderNodeVectorMath")
        horizon_mix_n.name = horizon_mix_n.label = Water.HORIZON_MIX_NODE
        horizon_mix_n.location = (start_pos_x + pos_x_shift * 5,
                                  start_pos_y + 1200)
        horizon_mix_n.operation = "MULTIPLY"

        lay0_lay1_normal_mix_n = node_tree.nodes.new("ShaderNodeVectorMath")
        lay0_lay1_normal_mix_n.name = lay0_lay1_normal_mix_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        lay0_lay1_normal_mix_n.location = (start_pos_x + pos_x_shift * 6,
                                           start_pos_y + 700)
        lay0_lay1_normal_mix_n.operation = "ADD"

        normal_normalize_n = node_tree.nodes.new("ShaderNodeVectorMath")
        normal_normalize_n.name = normal_normalize_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        normal_normalize_n.location = (start_pos_x + pos_x_shift * 7,
                                       start_pos_y + 700)
        normal_normalize_n.operation = "NORMALIZE"

        near_horizon_env_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_horizon_env_mix_n.name = near_horizon_env_mix_n.label = Water.NEAR_HORIZON_ENV_MIX_NODE
        near_horizon_env_mix_n.location = (start_pos_x + pos_x_shift * 7,
                                           start_pos_y + 2100)
        near_horizon_env_mix_n.blend_type = "MIX"
        near_horizon_env_mix_n.inputs['Color2'].default_value = (
            0.0, ) * 4  # far horizon is without env, thus lerp to zero

        near_horizon_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_horizon_mix_n.name = near_horizon_mix_n.label = Water.NEAR_HORIZON_MIX_NODE
        near_horizon_mix_n.location = (start_pos_x + pos_x_shift * 7,
                                       start_pos_y + 1700)
        near_horizon_mix_n.blend_type = "MIX"

        normal_scramble_n = node_tree.nodes.new("ShaderNodeMixRGB")
        normal_scramble_n.name = normal_scramble_n.label = Water.LAY0_LAY1_NORMAL_SCRAMBLE_NODE
        normal_scramble_n.location = (start_pos_x + pos_x_shift * 8,
                                      start_pos_y + 1200)
        normal_scramble_n.blend_type = "MIX"
        normal_scramble_n.inputs['Color1'].default_value = (0.0, 0.0, 1.0, 0.0
                                                            )  # WATER_V_NORMAL

        # links creation
        # pass 2
        node_tree.links.new(normal_normalize_n.inputs[0],
                            lay0_lay1_normal_mix_n.outputs[0])
        node_tree.links.new(vcol_mult_n.inputs[1], diff_col_n.outputs['Color'])

        # pass 3
        node_tree.links.new(near_mix_n.inputs[0], vcol_mult_n.outputs[0])
        node_tree.links.new(near_mix_n.inputs[1], near_col_n.outputs['Color'])

        node_tree.links.new(horizon_mix_n.inputs[0], vcol_mult_n.outputs[0])
        node_tree.links.new(horizon_mix_n.inputs[1],
                            horizon_col_n.outputs['Color'])

        node_tree.links.new(normal_scramble_n.inputs['Fac'],
                            mix_factor_n.outputs['Scramble Mix Factor'])
        node_tree.links.new(normal_scramble_n.inputs['Color2'],
                            normal_normalize_n.outputs['Vector'])

        # pass 5
        node_tree.links.new(near_horizon_env_mix_n.inputs['Fac'],
                            mix_factor_n.outputs['Mix Factor'])
        node_tree.links.new(near_horizon_env_mix_n.inputs['Color1'],
                            near_mix_n.outputs[0])

        node_tree.links.new(near_horizon_mix_n.inputs['Fac'],
                            mix_factor_n.outputs['Mix Factor'])
        node_tree.links.new(near_horizon_mix_n.inputs['Color1'],
                            near_mix_n.outputs[0])
        node_tree.links.new(near_horizon_mix_n.inputs['Color2'],
                            horizon_mix_n.outputs[0])

        # pass 6
        node_tree.links.new(lighting_eval_n.inputs['Normal Vector'],
                            normal_scramble_n.outputs['Color'])

        # pass 7
        node_tree.links.new(compose_lighting_n.inputs['Env Color'],
                            near_horizon_env_mix_n.outputs['Color'])
        node_tree.links.new(compose_lighting_n.inputs['Diffuse Color'],
                            near_horizon_mix_n.outputs['Color'])

        # add environment pass and normal maps
        StdAddEnv.add(
            node_tree, Dif.GEOM_NODE,
            node_tree.nodes[Dif.SPEC_COL_NODE].outputs['Color'], None,
            node_tree.nodes[Water.LIGHTING_EVAL_NODE].outputs['Normal'],
            node_tree.nodes[Water.NEAR_HORIZON_ENV_MIX_NODE].inputs['Color1'])

        node_tree.nodes[StdAddEnv.ADD_ENV_GROUP_NODE].inputs[
            'Base Texture Alpha'].default_value = 1  # set full reflection strength

        Water.__init_nmap__(node_tree, Water.LAYER0_NMAP_UID,
                            (start_pos_x + pos_x_shift, start_pos_y + 800),
                            geom_n.outputs['Position'],
                            water_stream_n.outputs['Stream0'],
                            geom_n.outputs['Normal'],
                            lay0_lay1_normal_mix_n.inputs[0])

        Water.__init_nmap__(node_tree, Water.LAYER1_NMAP_UID,
                            (start_pos_x + pos_x_shift, start_pos_y + 500),
                            geom_n.outputs['Position'],
                            water_stream_n.outputs['Stream1'],
                            geom_n.outputs['Normal'],
                            lay0_lay1_normal_mix_n.inputs[1])
Ejemplo n.º 21
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        vcol_group_n = node_tree.nodes[Dif.VCOL_GROUP_NODE]
        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        vcol_scale_n = node_tree.nodes[Dif.VCOLOR_SCALE_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        # node creation
        sec_uv_n = node_tree.nodes.new("ShaderNodeUVMap")
        sec_uv_n.name = sec_uv_n.label = DifWeightDif.SEC_UVMAP_NODE
        sec_uv_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1100)
        sec_uv_n.uv_map = _MESH_consts.none_uv

        over_tex_n = node_tree.nodes.new("ShaderNodeTexImage")
        over_tex_n.name = over_tex_n.label = DifWeightDif.OVER_TEX_NODE
        over_tex_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1200)
        over_tex_n.width = 140

        spec_mult_n = node_tree.nodes.new("ShaderNodeVectorMath")
        spec_mult_n.name = spec_mult_n.label = DifWeightDif.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 1900)
        spec_mult_n.operation = "MULTIPLY"

        base_over_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_over_mix_n.name = base_over_mix_n.label = DifWeightDif.BASE_OVER_MIX_NODE
        base_over_mix_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1300)
        base_over_mix_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(over_tex_n.inputs['Vector'], sec_uv_n.outputs['UV'])

        # pass 1
        node_tree.links.new(base_over_mix_n.inputs['Fac'], vcol_group_n.outputs['Vertex Color Alpha'])
        node_tree.links.new(base_over_mix_n.inputs['Color1'], base_tex_n.outputs['Color'])
        node_tree.links.new(base_over_mix_n.inputs['Color2'], over_tex_n.outputs['Color'])

        # pass 2
        node_tree.links.new(spec_mult_n.inputs[0], spec_col_n.outputs[0])
        node_tree.links.new(spec_mult_n.inputs[1], vcol_scale_n.outputs[0])

        node_tree.links.new(vcol_mult_n.inputs[1], base_over_mix_n.outputs['Color'])

        # pass to material
        node_tree.links.new(compose_lighting_n.inputs['Specular Color'], spec_mult_n.outputs[0])
        node_tree.links.new(compose_lighting_n.inputs['Alpha'], base_tex_n.outputs['Alpha'])
Ejemplo n.º 22
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        # nodes creation
        anim_speed_n = node_tree.nodes.new("ShaderNodeValue")
        anim_speed_n.name = anim_speed_n.label = DifAnim.ANIM_SPEED_NODE
        anim_speed_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1100)

        sec_uvmap_n = node_tree.nodes.new("ShaderNodeUVMap")
        sec_uvmap_n.name = sec_uvmap_n.label = DifAnim.SEC_UVMAP_NODE
        sec_uvmap_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1000)
        sec_uvmap_n.uv_map = _MESH_consts.none_uv

        blend_fac_gn = node_tree.nodes.new("ShaderNodeGroup")
        blend_fac_gn.name = blend_fac_gn.label = anim_blend_factor_ng.BLEND_FACTOR_G
        blend_fac_gn.location = (start_pos_x + pos_x_shift, start_pos_y + 1200)
        blend_fac_gn.node_tree = anim_blend_factor_ng.get_node_group()

        over_tex_n = node_tree.nodes.new("ShaderNodeTexImage")
        over_tex_n.name = over_tex_n.label = DifAnim.OVER_TEX_NODE
        over_tex_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1000)
        over_tex_n.width = 140

        base_over_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_over_mix_n.name = base_over_mix_n.label = DifAnim.BASE_OVER_MIX_NODE
        base_over_mix_n.location = (start_pos_x + pos_x_shift * 3,
                                    start_pos_y + 1300)
        base_over_mix_n.blend_type = "MIX"

        opacity_n = node_tree.nodes.new("ShaderNodeMixRGB")
        opacity_n.name = opacity_n.label = Dif.OPACITY_NODE
        opacity_n.location = (start_pos_x + pos_x_shift * 3,
                              start_pos_y + 1100)
        opacity_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(blend_fac_gn.inputs['Speed'],
                            anim_speed_n.outputs[0])
        node_tree.links.new(over_tex_n.inputs['Vector'],
                            sec_uvmap_n.outputs['UV'])

        # pass 1
        node_tree.links.new(base_over_mix_n.inputs['Fac'],
                            blend_fac_gn.outputs['Factor'])
        node_tree.links.new(base_over_mix_n.inputs['Color1'],
                            base_tex_n.outputs['Color'])
        node_tree.links.new(base_over_mix_n.inputs['Color2'],
                            over_tex_n.outputs['Color'])

        node_tree.links.new(opacity_n.inputs['Fac'],
                            blend_fac_gn.outputs['Factor'])
        node_tree.links.new(opacity_n.inputs['Color1'],
                            base_tex_n.outputs['Alpha'])
        node_tree.links.new(opacity_n.inputs['Color2'],
                            over_tex_n.outputs['Alpha'])

        # pass 2
        node_tree.links.new(vcol_mult_n.inputs[1],
                            base_over_mix_n.outputs['Color'])

        # pass 3
        node_tree.links.new(compose_lighting_n.inputs['Alpha'],
                            opacity_n.outputs['Color'])
Ejemplo n.º 23
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        NODE: this is fake representation only to utilize textures

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        diff_col_n = node_tree.nodes[Dif.DIFF_COL_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]
        output_n = node_tree.nodes[Dif.OUTPUT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.BASE_TEX_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.DIFF_MULT_NODE])

        # move existing

        vcol_mult_n.location.y -= 0
        out_mat_n.location.x += pos_x_shift * 2
        output_n.location.x += pos_x_shift * 2

        # nodes creation
        mix_factor_gn = node_tree.nodes.new("ShaderNodeGroup")
        mix_factor_gn.name = mix_factor_gn.label = Water.MIX_FACTOR_GNODE
        mix_factor_gn.location = (start_pos_x + pos_x_shift, start_pos_y + 1500)
        mix_factor_gn.node_tree = mix_factor_ng.get_node_group()

        near_col_n = node_tree.nodes.new("ShaderNodeRGB")
        near_col_n.label = near_col_n.name = Water.NEAR_COLOR_NODE
        near_col_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1300)

        horizon_col_n = node_tree.nodes.new("ShaderNodeRGB")
        horizon_col_n.label = horizon_col_n.name = Water.HORIZON_COLOR_NODE
        horizon_col_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1100)

        layer0_mat_n = node_tree.nodes.new("ShaderNodeMaterial")
        layer0_mat_n.name = layer0_mat_n.label = Water.LAYER0_MAT_NODE
        layer0_mat_n.location = (start_pos_x + pos_x_shift, start_pos_y + 900)
        layer0_mat_n.use_diffuse = False
        layer0_mat_n.use_specular = False

        layer1_mat_n = node_tree.nodes.new("ShaderNodeMaterial")
        layer1_mat_n.name = layer1_mat_n.label = Water.LAYER1_MAT_NODE
        layer1_mat_n.location = (start_pos_x + pos_x_shift, start_pos_y + 500)
        layer1_mat_n.use_diffuse = False
        layer1_mat_n.use_specular = False

        lay0_lay1_normal_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        lay0_lay1_normal_mix_n.name = lay0_lay1_normal_mix_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        lay0_lay1_normal_mix_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 700)
        lay0_lay1_normal_mix_n.blend_type = "ADD"
        lay0_lay1_normal_mix_n.inputs["Fac"].default_value = 1.0

        normal_normalize_n = node_tree.nodes.new("ShaderNodeVectorMath")
        normal_normalize_n.name = normal_normalize_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        normal_normalize_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 700)
        normal_normalize_n.operation = "NORMALIZE"

        near_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_mix_n.name = near_mix_n.label = Water.NEAR_MIX_NODE
        near_mix_n.location = (start_pos_x + pos_x_shift * 5, start_pos_y + 1400)
        near_mix_n.blend_type = "MULTIPLY"
        near_mix_n.inputs["Fac"].default_value = 1.0

        horizon_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        horizon_mix_n.name = horizon_mix_n.label = Water.HORIZON_MIX_NODE
        horizon_mix_n.location = (start_pos_x + pos_x_shift * 5, start_pos_y + 1200)
        horizon_mix_n.blend_type = "MULTIPLY"
        horizon_mix_n.inputs["Fac"].default_value = 1.0

        near_horizon_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_horizon_mix_n.name = near_horizon_mix_n.label = Water.NEAR_HORIZON_MIX_NODE
        near_horizon_mix_n.location = (start_pos_x + pos_x_shift * 6, start_pos_y + 1700)
        near_horizon_mix_n.blend_type = "MIX"

        # add environment pass and normal maps
        StdAddEnv.add(node_tree, Dif.GEOM_NODE, Dif.SPEC_COL_NODE, "", Water.NEAR_MIX_NODE, Water.NEAR_HORIZON_MIX_NODE)

        # links creation
        # pass 1
        node_tree.links.new(lay0_lay1_normal_mix_n.inputs["Color1"], layer0_mat_n.outputs["Normal"])
        node_tree.links.new(lay0_lay1_normal_mix_n.inputs["Color2"], layer1_mat_n.outputs["Normal"])

        # pass 2
        node_tree.links.new(normal_normalize_n.inputs[0], lay0_lay1_normal_mix_n.outputs["Color"])

        # pass 3
        node_tree.links.new(near_mix_n.inputs["Color1"], vcol_mult_n.outputs["Color"])
        node_tree.links.new(near_mix_n.inputs["Color2"], near_col_n.outputs["Color"])

        node_tree.links.new(horizon_mix_n.inputs["Color1"], vcol_mult_n.outputs["Color"])
        node_tree.links.new(horizon_mix_n.inputs["Color2"], horizon_col_n.outputs["Color"])

        # pass 4
        node_tree.links.new(vcol_mult_n.inputs["Color2"], diff_col_n.outputs["Color"])

        # pass 5
        node_tree.links.new(near_horizon_mix_n.inputs["Fac"], mix_factor_gn.outputs["Mix Factor"])
        node_tree.links.new(near_horizon_mix_n.inputs["Color2"], horizon_mix_n.outputs["Color"])

        # material pass
        node_tree.links.new(out_mat_n.inputs["Color"], near_horizon_mix_n.outputs["Color"])
        node_tree.links.new(out_mat_n.inputs["Normal"], normal_normalize_n.outputs["Vector"])
Ejemplo n.º 24
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        NODE: this is fake representation only to utilize textures

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        diff_col_n = node_tree.nodes[Dif.DIFF_COL_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]
        output_n = node_tree.nodes[Dif.OUTPUT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.BASE_TEX_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])
        node_tree.nodes.remove(node_tree.nodes[Dif.DIFF_MULT_NODE])

        # move existing

        vcol_mult_n.location.y -= 0
        out_mat_n.location.x += pos_x_shift * 2
        output_n.location.x += pos_x_shift * 2

        # nodes creation
        mix_factor_gn = node_tree.nodes.new("ShaderNodeGroup")
        mix_factor_gn.name = mix_factor_gn.label = Water.MIX_FACTOR_GNODE
        mix_factor_gn.location = (start_pos_x + pos_x_shift, start_pos_y + 1500)
        mix_factor_gn.node_tree = mix_factor_ng.get_node_group()

        near_col_n = node_tree.nodes.new("ShaderNodeRGB")
        near_col_n.label = near_col_n.name = Water.NEAR_COLOR_NODE
        near_col_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1300)

        horizon_col_n = node_tree.nodes.new("ShaderNodeRGB")
        horizon_col_n.label = horizon_col_n.name = Water.HORIZON_COLOR_NODE
        horizon_col_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1100)

        layer0_mat_n = node_tree.nodes.new("ShaderNodeMaterial")
        layer0_mat_n.name = layer0_mat_n.label = Water.LAYER0_MAT_NODE
        layer0_mat_n.location = (start_pos_x + pos_x_shift, start_pos_y + 900)
        layer0_mat_n.use_diffuse = False
        layer0_mat_n.use_specular = False

        layer1_mat_n = node_tree.nodes.new("ShaderNodeMaterial")
        layer1_mat_n.name = layer1_mat_n.label = Water.LAYER1_MAT_NODE
        layer1_mat_n.location = (start_pos_x + pos_x_shift, start_pos_y + 500)
        layer1_mat_n.use_diffuse = False
        layer1_mat_n.use_specular = False

        lay0_lay1_normal_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        lay0_lay1_normal_mix_n.name = lay0_lay1_normal_mix_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        lay0_lay1_normal_mix_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 700)
        lay0_lay1_normal_mix_n.blend_type = "ADD"
        lay0_lay1_normal_mix_n.inputs['Fac'].default_value = 1.0

        normal_normalize_n = node_tree.nodes.new("ShaderNodeVectorMath")
        normal_normalize_n.name = normal_normalize_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        normal_normalize_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 700)
        normal_normalize_n.operation = "NORMALIZE"

        near_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_mix_n.name = near_mix_n.label = Water.NEAR_MIX_NODE
        near_mix_n.location = (start_pos_x + pos_x_shift * 5, start_pos_y + 1400)
        near_mix_n.blend_type = "MULTIPLY"
        near_mix_n.inputs['Fac'].default_value = 1.0

        horizon_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        horizon_mix_n.name = horizon_mix_n.label = Water.HORIZON_MIX_NODE
        horizon_mix_n.location = (start_pos_x + pos_x_shift * 5, start_pos_y + 1200)
        horizon_mix_n.blend_type = "MULTIPLY"
        horizon_mix_n.inputs['Fac'].default_value = 1.0

        add_refl_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        add_refl_mix_n.name = add_refl_mix_n.label = Water.ADD_REFL_MIX_NODE
        add_refl_mix_n.location = (start_pos_x + pos_x_shift * 6, start_pos_y + 2000)
        add_refl_mix_n.blend_type = "ADD"
        add_refl_mix_n.inputs['Fac'].default_value = 1.0

        near_horizon_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        near_horizon_mix_n.name = near_horizon_mix_n.label = Water.NEAR_HORIZON_MIX_NODE
        near_horizon_mix_n.location = (start_pos_x + pos_x_shift * 7, start_pos_y + 1700)
        near_horizon_mix_n.blend_type = "MIX"

        # add environment pass and normal maps
        StdAddEnv.add(node_tree,
                      Dif.GEOM_NODE,
                      node_tree.nodes[Dif.SPEC_COL_NODE].outputs['Color'],
                      None,
                      None,
                      node_tree.nodes[Water.ADD_REFL_MIX_NODE].inputs['Color1'])

        # links creation
        # pass 1
        node_tree.links.new(lay0_lay1_normal_mix_n.inputs['Color1'], layer0_mat_n.outputs['Normal'])
        node_tree.links.new(lay0_lay1_normal_mix_n.inputs['Color2'], layer1_mat_n.outputs['Normal'])

        # pass 2
        node_tree.links.new(normal_normalize_n.inputs[0], lay0_lay1_normal_mix_n.outputs['Color'])
        node_tree.links.new(vcol_mult_n.inputs['Color2'], diff_col_n.outputs['Color'])

        # pass 3
        node_tree.links.new(near_mix_n.inputs['Color1'], vcol_mult_n.outputs['Color'])
        node_tree.links.new(near_mix_n.inputs['Color2'], near_col_n.outputs['Color'])

        node_tree.links.new(horizon_mix_n.inputs['Color1'], vcol_mult_n.outputs['Color'])
        node_tree.links.new(horizon_mix_n.inputs['Color2'], horizon_col_n.outputs['Color'])

        # pass 4
        node_tree.links.new(add_refl_mix_n.inputs['Color2'], near_mix_n.outputs['Color'])

        # pass 5
        node_tree.links.new(near_horizon_mix_n.inputs['Fac'], mix_factor_gn.outputs['Mix Factor'])
        node_tree.links.new(near_horizon_mix_n.inputs['Color1'], add_refl_mix_n.outputs['Color'])
        node_tree.links.new(near_horizon_mix_n.inputs['Color2'], horizon_mix_n.outputs['Color'])

        # material pass
        node_tree.links.new(out_mat_n.inputs['Color'], near_horizon_mix_n.outputs['Color'])
        node_tree.links.new(out_mat_n.inputs['Normal'], normal_normalize_n.outputs['Vector'])

        # output pass
        node_tree.links.new(output_n.inputs['Color'], out_mat_n.outputs['Color'])
Ejemplo n.º 25
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        vcol_group_n = node_tree.nodes[Dif.VCOL_GROUP_NODE]
        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        spec_col_n = node_tree.nodes[Dif.SPEC_COL_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]
        out_mat_n = node_tree.nodes[Dif.OUT_MAT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        # node creation
        sec_geom_n = node_tree.nodes.new("ShaderNodeGeometry")
        sec_geom_n.name = sec_geom_n.label = DifWeightDif.SEC_GEOM_NODE
        sec_geom_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1200)
        sec_geom_n.uv_layer = _MESH_consts.none_uv

        over_tex_n = node_tree.nodes.new("ShaderNodeTexture")
        over_tex_n.name = over_tex_n.label = DifWeightDif.OVER_TEX_NODE
        over_tex_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1200)

        spec_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_mult_n.name = spec_mult_n.label = DifWeightDif.SPEC_MULT_NODE
        spec_mult_n.location = (start_pos_x + pos_x_shift * 4,
                                start_pos_y + 1900)
        spec_mult_n.blend_type = "MULTIPLY"
        spec_mult_n.inputs['Fac'].default_value = 1

        base_over_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_over_mix_n.name = base_over_mix_n.label = DifWeightDif.BASE_OVER_MIX_NODE
        base_over_mix_n.location = (start_pos_x + pos_x_shift * 3,
                                    start_pos_y + 1300)
        base_over_mix_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(over_tex_n.inputs['Vector'],
                            sec_geom_n.outputs['UV'])

        # pass 1
        node_tree.links.new(base_over_mix_n.inputs['Fac'],
                            vcol_group_n.outputs['Vertex Color Alpha'])
        node_tree.links.new(base_over_mix_n.inputs['Color1'],
                            base_tex_n.outputs['Color'])
        node_tree.links.new(base_over_mix_n.inputs['Color2'],
                            over_tex_n.outputs['Color'])

        # pass 2
        node_tree.links.new(spec_mult_n.inputs['Color1'],
                            spec_col_n.outputs['Color'])
        node_tree.links.new(spec_mult_n.inputs['Color2'],
                            vcol_group_n.outputs['Vertex Color'])

        node_tree.links.new(vcol_mult_n.inputs['Color2'],
                            base_over_mix_n.outputs['Color'])

        # pass to material
        node_tree.links.new(out_mat_n.inputs['Spec'],
                            spec_mult_n.outputs['Color'])
Ejemplo n.º 26
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]
        vcol_mult_n = node_tree.nodes[Dif.VCOLOR_MULT_NODE]

        # delete existing
        node_tree.nodes.remove(node_tree.nodes[Dif.OPACITY_NODE])

        # nodes creation
        anim_speed_n = node_tree.nodes.new("ShaderNodeValue")
        anim_speed_n.name = anim_speed_n.label = DifAnim.ANIM_SPEED_NODE
        anim_speed_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1100)

        sec_geom_n = node_tree.nodes.new("ShaderNodeGeometry")
        sec_geom_n.name = sec_geom_n.label = DifAnim.SEC_GEOM_NODE
        sec_geom_n.location = (start_pos_x - pos_x_shift, start_pos_y + 1000)
        sec_geom_n.uv_layer = _MESH_consts.none_uv

        blend_fac_gn = node_tree.nodes.new("ShaderNodeGroup")
        blend_fac_gn.name = blend_fac_gn.label = anim_blend_factor_ng.BLEND_FACTOR_G
        blend_fac_gn.location = (start_pos_x + pos_x_shift, start_pos_y + 1200)
        blend_fac_gn.node_tree = anim_blend_factor_ng.get_node_group()

        over_tex_n = node_tree.nodes.new("ShaderNodeTexture")
        over_tex_n.name = over_tex_n.label = DifAnim.OVER_TEX_NODE
        over_tex_n.location = (start_pos_x + pos_x_shift, start_pos_y + 1000)

        base_over_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_over_mix_n.name = base_over_mix_n.label = DifAnim.BASE_OVER_MIX_NODE
        base_over_mix_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1300)
        base_over_mix_n.blend_type = "MIX"

        opacity_n = node_tree.nodes.new("ShaderNodeMixRGB")
        opacity_n.name = opacity_n.label = Dif.OPACITY_NODE
        opacity_n.location = (start_pos_x + pos_x_shift * 3, start_pos_y + 1100)
        opacity_n.blend_type = "MIX"

        # links creation
        node_tree.links.new(blend_fac_gn.inputs['Speed'], anim_speed_n.outputs[0])
        node_tree.links.new(over_tex_n.inputs['Vector'], sec_geom_n.outputs['UV'])

        # pass 1
        node_tree.links.new(base_over_mix_n.inputs['Fac'], blend_fac_gn.outputs['Factor'])
        node_tree.links.new(base_over_mix_n.inputs['Color1'], base_tex_n.outputs['Color'])
        node_tree.links.new(base_over_mix_n.inputs['Color2'], over_tex_n.outputs['Color'])

        node_tree.links.new(opacity_n.inputs['Fac'], blend_fac_gn.outputs['Factor'])
        node_tree.links.new(opacity_n.inputs['Color1'], base_tex_n.outputs['Value'])
        node_tree.links.new(opacity_n.inputs['Color2'], over_tex_n.outputs['Value'])

        # pass 2
        node_tree.links.new(vcol_mult_n.inputs['Color2'], base_over_mix_n.outputs['Color'])
Ejemplo n.º 27
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        pos_x_shift = 185

        # init parent
        Dif.init(node_tree)

        output_n = node_tree.nodes[Dif.OUTPUT_NODE]
        compose_lighting_n = node_tree.nodes[Dif.COMPOSE_LIGHTING_NODE]
        base_tex_n = node_tree.nodes[Dif.BASE_TEX_NODE]

        # move existing
        output_n.location.x += pos_x_shift * 3

        # nodes creation
        lum_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        lum_mix_n.name = DifLum.LUM_MIX_NODE
        lum_mix_n.label = DifLum.LUM_MIX_NODE
        lum_mix_n.location = (compose_lighting_n.location.x + pos_x_shift * 2,
                              compose_lighting_n.location.y - 100)
        lum_mix_n.blend_type = "MIX"

        lum_a_inv_n = node_tree.nodes.new("ShaderNodeMath")
        lum_a_inv_n.name = lum_a_inv_n.label = DifLum.LUM_A_INVERSE_NODE
        lum_a_inv_n.location = (compose_lighting_n.location.x +
                                pos_x_shift * 2,
                                compose_lighting_n.location.y - 300)
        lum_a_inv_n.operation = "SUBTRACT"
        lum_a_inv_n.use_clamp = True
        lum_a_inv_n.inputs[
            0].default_value = 0.999999  # TODO: change back to 1.0 after bug is fixed: https://developer.blender.org/T71426

        lum_out_shader_n = node_tree.nodes.new("ShaderNodeEeveeSpecular")
        lum_out_shader_n.name = lum_out_shader_n.label = DifLum.LUM_OUT_SHADER_NODE
        lum_out_shader_n.location = (compose_lighting_n.location.x +
                                     pos_x_shift * 3,
                                     compose_lighting_n.location.y - 200)
        lum_out_shader_n.inputs["Base Color"].default_value = (0.0, ) * 4
        lum_out_shader_n.inputs["Specular"].default_value = (0.0, ) * 4

        # links creation
        node_tree.links.new(lum_mix_n.inputs['Fac'],
                            base_tex_n.outputs['Alpha'])
        node_tree.links.new(lum_mix_n.inputs['Color1'],
                            compose_lighting_n.outputs['Color'])
        node_tree.links.new(lum_mix_n.inputs['Color2'],
                            base_tex_n.outputs['Color'])

        node_tree.links.new(lum_a_inv_n.inputs[1],
                            compose_lighting_n.outputs['Alpha'])

        node_tree.links.new(lum_out_shader_n.inputs['Emissive Color'],
                            lum_mix_n.outputs['Color'])
        node_tree.links.new(lum_out_shader_n.inputs['Transparency'],
                            lum_a_inv_n.outputs['Value'])

        node_tree.links.new(output_n.inputs['Surface'],
                            lum_out_shader_n.outputs['BSDF'])