Exemplo 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 parents
        DifSpecMultDifSpec.init(node_tree)
        StdAddEnv.add(node_tree,
                      DifSpecMultDifSpec.GEOM_NODE,
                      DifSpecMultDifSpec.SPEC_COL_NODE,
                      DifSpecMultDifSpec.BASE_TEX_NODE,
                      DifSpecMultDifSpec.OUT_MAT_NODE,
                      DifSpecMultDifSpec.OUTPUT_NODE)
Exemplo n.º 2
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"])