# Simplygon Shading Network functions

The Simplygon Max plug-in exports a number of global MaxScript / Python functions. The following sections lists Simplygon ShadingNetwork functions and examples, general Simplygon functions and Simplygon Pipeline functions are listed separately.

Shading networks are usually generated automatically in the plug-in but for some material types, such as DirectX and CGFX (HLSL), the mapping has to be done manually. It is recommended to read Shading network concepts before proceeding.

# Script functions

Function Parameter(s) Description
sgsdk_RunPipelineOnSelection int pipelineHandle Optimizes the selected asset(s) based on the pipeline object.
sgsdk_RunPipelineOnSelection string pipelineFilePath Optimizes the selected asset(s) based on the pipeline file.
sgsdk_RunPipelineOnFile int pipelineHandle
string inputFilePath
string outputFilePath
Optimizes the asset(s) in the specified input file and stores the result in the output file. The output file will get indexed if the Pipeline specifies a LOD chain, use sgsdk_GetProcessedOutputPaths to get the correct paths.
sgsdk_RunPipelineOnFile string pipelineFilePath
string inputFilePath
string outputFilePath
Optimizes the asset(s) in the specified input file and stores the result in the output file. The output file will get indexed if the Pipeline specifies a LOD chain, use sgsdk_GetProcessedOutputPaths to get the correct paths.
sgsdk_UseShadingNetwork bool isEnabled Enables shading network pipeline.
sgsdk_CreateMaterialMetadata string materialName Creates an override material for the named material.
sgsdk_CreateShadingTextureNode string textureName Creates a texture node that connects to the given texture name in the shader.
sgsdk_CreateShading<nodeType>
Ex: sgsdk_CreateShadingColorNode
string nodeName Creates a node of the given type.
sgsdk_SetDefaultParameter int nodeIndex
uint inputSlot
double a
double b
double c
double d
Sets default values for the given node input.
sgsdk_AddAttributeToNode int nodeIndex
uint inputSlot
Sets an attribute to the specified node.
sgsdk_ConnectNodes int nodeIndex
uint inputSlot
int nodeIndexToConnect
Connects a node to another node’s input slot.
sgsdk_ConnectNodeToChannel int nodeIndex
int materialIndex
string channelName
Sets the exit node for the given material channel.
sgsdk_ConnectOutputToDirectXMaterial string effectFile
string channelName
string textureSlot
Specifies to which shader and texture slot the result will be connected to.
sgsdk_VertexColorNodeSetVertexChannel int nodeIndex
int mappingChannel
Specifies which color channel to read from.
sgsdk_SwizzlingNodeSetChannelSwizzle int nodeIndex
uint inputSlot
uint outputSlot
Sets output slot for the given input slot for the node, (RGBA -> 0, 1, 2, 3).
sgsdk_SetMappingChannel int nodeIndex
int mappingChannel
Sets the mapping channel/UV-set for the given texture node.
sgsdk_SetSRGB int nodeIndex
bool isSRGB
Sets the sRGB flag for the given texture node.
sgsdk_SetUVTiling int nodeIndex
float uTiling
float vTiling
Sets the UV-tiling for the given texture node.
sgsdk_SetUTiling int nodeIndex
float uTilingSets
Sets the U-tiling for the given texture node.
sgsdk_SetVTiling int nodeIndex
float vTiling
Sets the V-tiling for the given texture node.
sgsdk_SetUVOffset int nodeIndex
float uOffset
float vOffset
Sets the UV-offset for the given texture node
sgsdk_SetUOffset int nodeIndex
float uOffset
Sets the U-offset for the given texture node.
sgsdk_SetVOffset int nodeIndex
float vOffset
Sets the V-offset for the given texture node.
sgsdk_GetProcessedMeshes <none> Returns a list of processed mesh names from last run.
sgsdk_GetProcessedOutputPaths <none> Returns a list of processed file paths from last run.
sgsdk_GetMaterialForMesh string meshName Return material name for the specified mesh.
sgsdk_GetMeshReusesMaterial string meshName Returns material name if the material is shared, otherwise empty string.
sgsdk_GetChannelsForMaterial string materialName Returns a list of material channel names for the specified material.
sgsdk_GetTexturePathForChannel string materialName
string channelName
Returns the texture path for the specified material channel.
sgsdk_GetMappingChannelForChannel string materialName
string channelName
Returns the mapping channel for the specified material channel.
sgsdk_GetMaterials <none> Returns a list of material names from the last run.
sgsdk_SetGenerateMaterial bool generateMaterial Specifies whether the plug-in should generate a standard material for baked LODs.
sgsdk_SetTextureOutputDirectory string filePath Sets the output texture directory for baked textures.

# Special node attributes

Special node attributes can be set using sgsdk_AddAttributeToNode, see the list of attributes below.

Shading Node Attribute Type
ShadingTextureNode 1 – TileU, 2 – TileV
3 – MappingChannel
4 – TileUV
5 – OffsetU, 6 – OffsetV
7 – OffsetUV

# Examples

This section contains various Pipeline examples written in MaxScript and Python. We've left out some parts of the scripts to keep things as simple as possible.

  • from pymxs import runtime as rt must be declared at the top of each Python script.
  • reductionPipeline settings-path must be declared for both MaxScript and Python scripts where it makes sense.
  • effectFile file-path to the target shader must be declared for both MaxScript and Python scripts where it makes sense.
  • a scene-selection is made before each sgsdk_RunPipelineOnSelection.

# Create material

Creates a shading network material override for the specified material.

    # Create node

    Creates a texture node that is linked to a shader's texture slot named DiffuseTexture.

      # Set default values

      Creates a pow node, connects a texture to input 0 and sets a value for input 1.

        # Set exit node

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

          # Set swizzle

          Creates a swizzle node with the same texture input on all input channels and swizzles the output channels (in reverse). (R->A, G->B, B->G, A->R)

            # Set vertex color mapping channel

            Creates a vertex color node and sets the node to read from mapping channel 0 (default vertex color channel in Max).

              # Override mapping channel / UV-set

              Creates a texture and overrides the mapping channel / UV-set.

                If we have the mapping channel exposed in the shader we can create a direct link between the texture node and mapping channel shader parameter using attributes. The Texture2D definition in the HLSL shader below contains a variable named MapChannel.

                  Note that the mapChannel in the line below starts with lowercase.

                    # Override sRGB

                    Overrides the sRGB flag for a texture node.

                      # Override tiling / offset

                      Creates a texture node and overrides the U/V-tiling and U/V-offset.

                        If tiling and / or offset parameters are defined in the HLSL shader it might be preferred to create a link between the texture node and the shader parameter(s) using attributes.

                          Link the texture node to the parameters.

                            # Back-mapping to custom shader

                            Specifies to which shader and texture slot the baked texture will get connected to after the processing has been completed.

                              # Next steps

                              Get to know how to work with shading networks: