Skip to content
On this page

Vertex-color blending

The following sections contain examples on how to blend colors using vertex-colors. It is recommended to read Shading network concepts before proceeding.

Vertex-color blending using InterpolateNode

This script sets up three vertex color nodes where the last one is used as blend weight. This example is based on the InterpolateNode.

MaxScript
DirectXShader = sgsdk_CreateMaterialMetadata MaterialName

    DiffuseTexture1 = sgsdk_CreateShadingTextureNode "DiffuseTexture1"
    sgsdk_AddAttributeToNode DiffuseTexture "DiffuseTexture1mapChannel" 3

    DiffuseTexture2 = sgsdk_CreateShadingTextureNode "DiffuseTexture2"
    sgsdk_AddAttributeToNode DiffuseTexture "DiffuseTexture2mapChannel" 3

    BlendColor = sgsdk_CreateShadingVertexColorNode "BlendColor"
    sgsdk_VertexColorNodeSetVertexChannel BlendColor 0

    InterpolateNode = sgsdk_CreateShadingInterpolateNode "InterpolateNode"
    sgsdk_ConnectNodes InterpolateNode 0 DiffuseTexture1
    sgsdk_ConnectNodes InterpolateNode 1 DiffuseTexture2
    sgsdk_ConnectNodes InterpolateNode 2 DefaultBlendColor

    sgsdk_ConnectNodeToChannel InterpolateNode DirectXShader "Diffuse"
    sgsdk_ConnectOutputToDirectXMaterial effectFile "Diffuse" "DiffuseTexture"
python
from pymxs import runtime as rt

DirectXShader = rt.sgsdk_CreateMaterialMetadata(MaterialName)

DiffuseTexture1 = rt.sgsdk_CreateShadingTextureNode('DiffuseTexture1')
rt.sgsdk_AddAttributeToNode(DiffuseTexture, 'DiffuseTexture1mapChannel', 3)

DiffuseTexture2 = rt.sgsdk_CreateShadingTextureNode('DiffuseTexture2')
rt.sgsdk_AddAttributeToNode(DiffuseTexture, 'DiffuseTexture2mapChannel', 3)

BlendColor = rt.sgsdk_CreateShadingVertexColorNode('BlendColor')
rt.sgsdk_VertexColorNodeSetVertexChannel(BlendColor, 0)

InterpolateNode = rt.sgsdk_CreateShadingInterpolateNode('InterpolateNode')
rt.sgsdk_ConnectNodes(InterpolateNode, 0, DiffuseTexture1)
rt.sgsdk_ConnectNodes(InterpolateNode, 1, DiffuseTexture2)
rt.sgsdk_ConnectNodes(InterpolateNode, 2, DefaultBlendColor)

rt.sgsdk_ConnectNodeToChannel(InterpolateNode, DirectXShader, 'Diffuse')
rt.sgsdk_ConnectOutputToDirectXMaterial(effectFile, 'Diffuse', 'DiffuseTexture')