Skip to content
On this page

SimplygonShadingNetwork command

Description

The SimplygonShadingNetwork command is responsible for creating shading network templates in Maya. Shading networks are usually generated automatically in the plug-in but for some material types, such as DirectX, CGFX and Stingray, the mapping has to be done manually. It is recommended to read Shading network concepts before proceeding.

Syntax

MEL
SimplygonShadingNetwork -<short/long flag> <arg0> <arg1> ... <argN>;
python
import maya.cmds as cmds
cmds.SimplygonShadingNetwork(<short/long flag>=<arg>)
cmds.SimplygonShadingNetwork(<short/long flag>=[<arg0>, <arg1>, ..., <argN>])

Flags and args

Short flagLong flagArgument(s)Description
cnCreateNodestring materialName
string nodeType
string nodeName
Creates a node of the given type.
siSetInputstring materialName
string nodeName
uint inputSlot
string nodeNameToConnect
Connects a node to another node’s input slot.
sdSetDefaultstring materialName
string nodeName
uint inputSlot
double A
double B
double C
Sets default values for the given node input.
sd1SetDefault1fstring materialName
string nodeName
uint inputSlot
uint component
double A
Sets default value for the given node input on the given component [RGBA, 0-3].
sceSetExitNodestring materialName
string channelName
string nodeName
Sets the exit node for the given material channel.
exfExportXMLstring materialName
string channelName
string filePath
Exports shading network for the given material channel to file.
swzSwizzlestring materialName
string nodeName
uint inputSlot
uint outputSlot
Sets output slot for the given input slot for the specified swizzle node
(RGBA -> 0, 1, 2, 3).
svnSetVertexColorNamestring materialName
string nodeName
string colorSetName
Sets which color set to sample from for the given vertex color node.
svcSetVertColstring materialName
string nodeName
uint colorSet
Sets which color set to sample from for the given vertex color node.
uvaSetUVAllstring nodeName
string uvSetName
Sets the UV-set for the texture nodes matching the specified node name.
uvmSetUVMaterialstring materialName
string nodeName
string uvSetName
Sets the UV-set for the texture nodes that matches the specified node name for the given material.
uvcSetUVMaterialChannelstring materialName
string channelName
string nodeName
string uvSetName
Sets the UV-set for the texture nodes that matches the specified node name for the given material channel.
saSetSRGBAllstring nodeName
bool isSRGB
Sets the sRGB flag for the texture nodes matching the specified node name.
smSetSRGBMaterialstring materialName
string nodeName
bool isSRGB
Sets the sRGB flag for the texture nodes that matches the specified node name for the given material.
scSetSRGBMaterialChannelstring materialName
string channelName
string nodeName
bool isSRGB
Sets the sRGB flag for the texture nodes that matches the specified node name for the given material channel.
tmcSetUVTilingMaterialChannelstring materialName
string channelName
string nodeName
double uTiling
double vTiling
Sets u- and v-tiling for the given texture node.
omcSetUVOffsetMaterialChannelstring materialName
string channelName
string nodeName
double uOffset
double vOffset
Sets u- and v-offset for the given texture node.
sgnSetGeometryFieldNamestring materialName
string nodeName
string geometryFieldName
Sets the field name for the given geometry field node.
sgiSetGeometryFieldIndexstring materialName
string nodeName
int geometryFieldIndex
Sets the field index for the given geometry field node.
sgtSetGeometryFieldTypestring materialName
string nodeName
int geometryFieldType
Sets the field type (EGeometryFieldType in Simplygon API) for the given geometry field node.

Examples

This section contains some examples on how to setup shading networks through MEL and Python. We've left out some parts of the scripts to keep things as simple as possible.

  • import maya.cmds as cmds must declared at the top of each Python script.
  • reductionPipeline settings-path must be declared for both MEL and Python scripts where it makes sense.
  • materialName is used as a place-holder for the name of the material we are currently working on.
  • a scene-selection is made before each Simplygon-command.

Create shading node

Creates two texture-nodes that points to the texture slots of the CGFX material's HLSL shader, in this case DiffuseSampler and NormalsSampler (as defined in the shader).

MEL
SimplygonShadingNetwork
    -cn $materialName TextureNode DiffuseSampler
    -cn $materialName TextureNode NormalsSampler;
python
cmds.SimplygonShadingNetwork(
    cn = [
            [materialName, 'TextureNode', 'DiffuseSampler'],
            [materialName, 'TextureNode', 'NormalsSampler']
         ])

For CGFX materials the sampler2D (DiffuseSampler) represents the texture slot. For DirectX materials the texture (DiffuseTexture) represents the texture slot. This means that we'll use the sampler2D when mapping textures from CGFX to Simplygon, and texture when mapping textures from DirectX to Simplygon.

:::tab HLSL

cs
texture DiffuseTexture : Diffuse
<
    string ResourceType = "2D";
    string UIName =  "Diffuse Texture";
>;
sampler2D DiffuseSampler = sampler_state
{
    Texture = <DiffuseTexture>;
    MinFilter = LinearMipMapLinear;
    MagFilter = Linear;
};

Set default values

Sets the default values of (for example) a Multiply-node. The name of the node is "multiplyNode".

MEL
SimplygonShadingNetwork
    -sd  $materialName multiplyNode 0 1.00 1.00 1.00
    -sd  $materialName multiplyNode 1 0.25 0.25 0.25
    -sd1 $materialName multiplyNode 0 3 1.00;
    -sd1 $materialName multiplyNode 1 3 1.00;
python
cmds.SimplygonShadingNetwork(
    sd  = [
            [materialName, 'multiplyNode', 0, 1.00, 1.00, 1.00],
            [materialName, 'multiplyNode', 1, 0.25, 0.25, 0.25],
          ],
    sd1 = [
            [materialName, 'multiplyNode', 0, 3, 1.00]
            [materialName, 'multiplyNode', 1, 3, 1.00]
          ])

Set exit node

Assigns a shading node to a material channel, in this case we connect as texture node (which points to DiffuseSampler in shader) to the Diffuse channel.

MEL
SimplygonShadingNetwork
    -sce $materialName Diffuse DiffuseSampler;
python
cmds.SimplygonShadingNetwork(
    sce = [materialName, 'Diffuse', 'DiffuseSampler'])

Set swizzle

Reverses the color channels (RGBA -> ABGR) using a swizzling node. The name of the node is "swizzleNode".

MEL
SimplygonShadingNetwork
    -si $materialName swizzleNode 0 DiffuseSampler
    -si $materialName swizzleNode 1 DiffuseSampler
    -si $materialName swizzleNode 2 DiffuseSampler
    -si $materialName swizzleNode 3 DiffuseSampler
    -swz $materialName swizzleNode 0 3
    -swz $materialName swizzleNode 1 2
    -swz $materialName swizzleNode 2 1
    -swz $materialName swizzleNode 3 0;
python
cmds.SimplygonShadingNetwork(
    si  = [
        [materialName, 'swizzleNode', 0, 'DiffuseSampler'],
        [materialName, 'swizzleNode', 1, 'DiffuseSampler'],
        [materialName, 'swizzleNode', 2, 'DiffuseSampler'],
        [materialName, 'swizzleNode', 3, 'DiffuseSampler']
    ],
    swz = [
        [materialName, 'swizzleNode', 0, 3],
        [materialName, 'swizzleNode', 1, 2],
        [materialName, 'swizzleNode', 2, 1],
        [materialName, 'swizzleNode', 3, 0]
    ])

Set vertex-color set

Assigns "colorSet1" (of the mesh) to a vertex-color node. Can be used to blend textures by vertex colors or bake vertex colors to texture. The name of the node is "vertexColorNode".

MEL
SimplygonShadingNetwork
    -svn $materialName vertexColorNode colorSet1;
python
cmds.SimplygonShadingNetwork(
    svn = [materialName, 'vertexColorNode', 'colorSet1'])

Specify geometry data field

Assigns a data field (of the mesh) to a geometry-field node. The node can be used to sample specific geometry fields in shading network such as Coords, TexCoords, Normals, Tangents, Bitangents, Colors, TriangleIds and MaterialIds (see EGeometryDataFieldType). In this example we will set up a geometry field node that samples from the color field 'colorSet1'.

SetGeometryFieldType (sgt) specifies which type of the field to sample from, as all colors are stored as 'Color'-fields in Simplygon we want to use the 'Color' index in EGeometryDataFieldType as the type, which is 5.

SetGeometryFieldName (sgn) and SetGeometryFieldIndex (sgi) specifies either the Name or Index of the Color field to sample from, Name har precedence over Index (index might also differ between meshes).

The name of the node is "geometryFieldNode".

MEL
SimplygonShadingNetwork
    -sgt $materialName geometryFieldNode 5
    -sgn $materialName geometryFieldNode colorSet1;
python
cmds.SimplygonShadingNetwork(
    sgt = [materialName, 'geometryFieldNode', 5],
    sgn = [materialName, 'geometryFieldNode', 'colorSet1'])

Override UV-set

Overrides a texture's UV-set (globally). The name of the texture node is "DiffuseSampler".

MEL
SimplygonShadingNetwork
    -uva DiffuseSampler map1;
python
cmds.SimplygonShadingNetwork(
    uva = ['DiffuseSampler', 'map1'])

Override sRGB

Overrides the sRGB-flag for Diffuse and Normals.

MEL
SimplygonShadingNetwork
    -sc $materialName Diffuse DiffuseSampler true
    -sc $materialName Normals NormalsSampler false;
python
cmds.SimplygonShadingNetwork(
    sc = [
            [materialName, 'Diffuse', 'DiffuseSampler', True],
            [materialName, 'Normals', 'NormalsSampler', False]
         ])

Override tiling/offset

Overrides a texture-node's tiling and offset values for the Diffuse channel. The name of the texture node is "DiffuseSampler".

MEL
SimplygonShadingNetwork
    -tmc $materialName Diffuse DiffuseSampler 2.0 2.0
    -omc $materialName Diffuse DiffuseSampler 0.5 0.5;
python
cmds.SimplygonShadingNetwork(
    tmc = [materialName, 'Diffuse', 'DiffuseSampler', 2.0, 2.0],
    omc = [materialName, 'Normals', 'DiffuseSampler', 0.5, 0.5])

Export Shading Network XML

Exports a shading network for the given material channel to XML.

MEL
SimplygonShadingNetwork
    -exf cgfx_leather Diffuse "C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml";
python
cmds.SimplygonShadingNetwork(
    exf = ['cgfx_leather', 'Diffuse', 'C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml'])

Import Shading Network XML

Imports shading network XML through the Simplygon command.

MEL
// specify Pipeline settings path
$reductionPipelineFilepath = "D:/Pipelines/ReductionPipelineWithBaking.json";

Simplygon
    -sf $reductionPipelineFilepath
    -asm cgfx_leather|cgfx_wood
    -ixf cgfx_leather Diffuse "C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml"
    -ixf cgfx_wood Diffuse "C:/ShadingNetworksTemp/cgfx_wood_diffuse.xml";
python
cmds.Simplygon(
    sf = reductionPipelineFilepath,
    asm = 'cgfx_leather|cgfx_wood',
    ixf = [
            'cgfx_leather', 'Diffuse', 'C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml'
          ],
    ixf = [
            'cgfx_wood', 'Diffuse', 'C:/ShadingNetworksTemp/cgfx_wood_diffuse.xml'
          ])