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
SimplygonShadingNetwork -<short/long flag> <arg0> <arg1> ... <argN>;
import maya.cmds as cmds
cmds.SimplygonShadingNetwork(<short/long flag>=<arg>)
cmds.SimplygonShadingNetwork(<short/long flag>=[<arg0>, <arg1>, ..., <argN>])
Flags and args
Short flag | Long flag | Argument(s) | Description |
---|---|---|---|
cn | CreateNode | string materialName string nodeType string nodeName | Creates a node of the given type. |
si | SetInput | string materialName string nodeName uint inputSlot string nodeNameToConnect | Connects a node to another node’s input slot. |
sd | SetDefault | string materialName string nodeName uint inputSlot double A double B double C | Sets default values for the given node input. |
sd1 | SetDefault1f | string materialName string nodeName uint inputSlot uint component double A | Sets default value for the given node input on the given component [RGBA, 0-3]. |
sce | SetExitNode | string materialName string channelName string nodeName | Sets the exit node for the given material channel. |
exf | ExportXML | string materialName string channelName string filePath | Exports shading network for the given material channel to file. |
swz | Swizzle | string 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). |
svn | SetVertexColorName | string materialName string nodeName string colorSetName | Sets which color set to sample from for the given vertex color node. |
svc | SetVertCol | string materialName string nodeName uint colorSet | Sets which color set to sample from for the given vertex color node. |
uva | SetUVAll | string nodeName string uvSetName | Sets the UV-set for the texture nodes matching the specified node name. |
uvm | SetUVMaterial | string materialName string nodeName string uvSetName | Sets the UV-set for the texture nodes that matches the specified node name for the given material. |
uvc | SetUVMaterialChannel | string 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. |
sa | SetSRGBAll | string nodeName bool isSRGB | Sets the sRGB flag for the texture nodes matching the specified node name. |
sm | SetSRGBMaterial | string materialName string nodeName bool isSRGB | Sets the sRGB flag for the texture nodes that matches the specified node name for the given material. |
sc | SetSRGBMaterialChannel | string 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. |
tmc | SetUVTilingMaterialChannel | string materialName string channelName string nodeName double uTiling double vTiling | Sets u- and v-tiling for the given texture node. |
omc | SetUVOffsetMaterialChannel | string materialName string channelName string nodeName double uOffset double vOffset | Sets u- and v-offset for the given texture node. |
sgn | SetGeometryFieldName | string materialName string nodeName string geometryFieldName | Sets the field name for the given geometry field node. |
sgi | SetGeometryFieldIndex | string materialName string nodeName int geometryFieldIndex | Sets the field index for the given geometry field node. |
sgt | SetGeometryFieldType | string 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).
SimplygonShadingNetwork
-cn $materialName TextureNode DiffuseSampler
-cn $materialName TextureNode NormalsSampler;
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.
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".
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;
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.
SimplygonShadingNetwork
-sce $materialName Diffuse DiffuseSampler;
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".
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;
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".
SimplygonShadingNetwork
-svn $materialName vertexColorNode colorSet1;
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".
SimplygonShadingNetwork
-sgt $materialName geometryFieldNode 5
-sgn $materialName geometryFieldNode colorSet1;
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".
SimplygonShadingNetwork
-uva DiffuseSampler map1;
cmds.SimplygonShadingNetwork(
uva = ['DiffuseSampler', 'map1'])
Override sRGB
Overrides the sRGB-flag for Diffuse and Normals.
SimplygonShadingNetwork
-sc $materialName Diffuse DiffuseSampler true
-sc $materialName Normals NormalsSampler false;
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".
SimplygonShadingNetwork
-tmc $materialName Diffuse DiffuseSampler 2.0 2.0
-omc $materialName Diffuse DiffuseSampler 0.5 0.5;
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.
SimplygonShadingNetwork
-exf cgfx_leather Diffuse "C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml";
cmds.SimplygonShadingNetwork(
exf = ['cgfx_leather', 'Diffuse', 'C:/ShadingNetworksTemp/cgfx_leather_diffuse.xml'])
Import Shading Network XML
Imports shading network XML through the Simplygon command.
// 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";
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'
])