Getting shader info from an ASS file


First, set things up so you can use the Arnold Python API. On Windows:

set PATH=C:\Users\blairs\AppData\Local\Programs\Python\Python39;%PATH%
set PYTHONPATH=C:\solidangle\arnold\Arnold-6.2.1.1-windows\python

rem Sometimes necessary
set PATH=C:\solidangle\arnold\Arnold-6.2.1.1-windows\bin;%PATH%

Then, run this Python script, which does the following:

  • Sets the logging verbosity
  • Loads an ASS file
  • Loops over all the shader nodes.
  • If a shader is a standard_surface, inspect the ID AOV parameters.
from arnold import *
AiBegin()
 
AiMsgSetConsoleFlags(AI_LOG_ALL)
 
# Required if the ASS file uses any SItoA shaders
#AiLoadPlugins('C:/softimage/workgroups/sitoa-3.4.0-2015/Addons/SItoA/Application/Plugins/bin/nt-x86-64')
 
AiASSLoad('C:/Users/blairs/Documents/maya/projects/default/scenes/denoiseme.0009.ass')
 
# Iterate over all shader nodes
iter = AiUniverseGetNodeIterator(AI_NODE_SHADER);
while not AiNodeIteratorFinished(iter):
    node = AiNodeIteratorGetNext(iter)
    print( "[script] AiNodeGetName: {0}".format( AiNodeGetName( node ) ) )

    ne = AiNodeGetNodeEntry( node )
#    print( "[script]  AiNodeEntryGetName: {0}".format( AiNodeEntryGetName( ne ) ) )
#    print( "[script]  AiNodeEntryGetType: {0}".format( AiNodeEntryGetType( ne ) ) )
#    print( "[script]  AiNodeEntryGetTypeName: {0}".format( AiNodeEntryGetTypeName( ne ) ) )

    if AiNodeIs( node, "standard_surface" ):
        
     
        # Plain color ID AOVs are easy
        aov_id1 = AiNodeGetStr( node, "aov_id1" )
        print( "[script]  aov_id1={0}".format( aov_id1 )  )   
        
        id1 = AiNodeGetRGB( node, "id1" )
        print( "[script]  id1={0} {1} {2}".format( id1.r, id1.g, id1.b)  )   


        # ID AOVs that use a linked shader take a bit more work     
        aov_id2 = AiNodeGetStr( node, "aov_id2" )
        print( "[script]  aov_id2={0}".format( aov_id2 )  )   
        if AiNodeIsLinked( node, "id2" ):
            id2 = AiNodeGetLink( node, "id2" )
            print( "[script]  id2={0}".format( AiNodeGetName( id2 ) ) )


AiNodeIteratorDestroy(iter)
AiEnd()

Kicking Bifrost ASS


You can export a Bifrost scene to an Arnold ass file and then render it with kick.

Just use the -l flag (or the ARNOLD_PLUGIN_PATH environment variable) to point to the Arnold plugins that comes with the Bifrost install. For example, on Windows:

kick -v 5 -dp bifrost_aeroColors.ass 
-l "C:\Program Files\Autodesk\Bifrost\Maya2020\2.2.0.2\bifrost\arnold-6.2.0.0"
kick render of a Bifrost graph

In the Arnold log, we see that Arnold loads the procedural nodes for Bifrost:

00:00:00 88MB | loading plugins from C:\Program Files\Autodesk\Bifrost\Maya2020\2.2.0.2\bifrost\arnold-6.2.0.0 …
00:00:00 100MB | arnold_bifrost.dll: bifrost_graph uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_object uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_multires_volume uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_multires_implicit uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_volume uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_points uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_implicit uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_polymesh uses Arnold 6.2.0.0
00:00:00 100MB | arnold_bifrost.dll: bifrost_blocks uses Arnold 6.2.0.0
00:00:00 100MB | loaded 9 plugins from 1 lib(s) in 0:00.06

In other applications, like CINEMA 4D or Houdini or Katana, you can do the same thing by setting the Plugin Search Path.

Arnold light_groups and shadow_groups


Light linking in Maya, include/exclude objects for lights in CINEMA 4D, light masks in Houdini, inclusive/exclusive lights in Softimage, they all are translated to light_groups and shadow_groups in Arnold.

Here’s a sphere on a plane, with two area lights (cyan and green).

default

If we add a light_group to the sphere polymesh:

 use_light_group on
 light_group "CyanAreaLight"

then we get this (see below). The sphere is lit only by the cyan area light: the light_group is the lights that affect the object.

light_group_on_cyan
Note that the sphere still casts shadows from the green light, even the sphere isn’t lit by the green light. That’s because there’s no shadow_group, so all lights cast shadows from the object.

If we add a shadow group, so that the light_group and shadow_group are both “CyanAreaLight”, then the sphere is lit by the cyan light only, and casts shadows from the cyan light only.

use_light_group on
 light_group "CyanAreaLight"
use_shadow_group on
 shadow_group "CyanAreaLight"

light_shadow_groups_on_cyan

And finally, here’s the sphere when light groups are on, but there’s no lights in the light group:

use_light_group on
use_shadow_group on
 shadow_group "CyanAreaLight"

light_group_empty

[FAQ] Can I transfer Arnold shaders to another app?


For example, can I transfer Arnold shaders from 3ds Max to Maya? Or from Houdini to Maya?

The answer is no. The Arnold plugins don’t include code for reading shader nodes from an ASS file and creating shader trees inside the host application (eg Maya, Houdini, or Cinema 4D).

You can use ASS files to take shapes and shaders from one app and render them in another app, but those shapes and shaders are never created inside the other app.

An MtoA Standin (aka an Arnold Procedural in HtoA and C4DtoA) references an ASS file, and passes that on to Arnold at render time.

standins

The ASS file contains Arnold nodes (shapes and shaders). Those Arnold nodes are not created inside the 3D application.

Instead, the standin node is translated to an Arnold procedural node, and at render time, that procedural node is expanded, and all the Arnold shapes and shaders are created inside the Arnold scene.

Exporting ASS files to specific locations


For the render -rt 1 command, you can specify the output ASS name in
the defaultArnoldRenderOptions.output_ass_filename attribute. For example:

set PRE_RENDER_MEL="setAttr -type \"string\" 
defaultArnoldRenderOptions.output_ass_filename 
 \"c:/Users/StephenBlair/Documents/example\";"
 
 render -s 6 -e 8 -r arnold -rt 1 -preRender %PRE_RENDER_MEL% 
 C:\projects\Support\scenes\_2016\XSI_deformed_logo.mb 

This will export ASS files named “example.ass”.

The scene should have the Frame/Animation ext set to something like
“name.#.ext”. Otherwise, if it is “name.ext” you’ll get filenames like
“example.ass.0004.ass”

output_ass_filename can have environment variables, but you have to be
careful to use forward slashes. For example:

set PRE_RENDER_MEL="setAttr -type \"string\" defaultArnoldRenderOptions.output_ass_filename \"%OUTPUT_ASS_FILENAME%\";" 
set OUTPUT_ASS_FILENAME=C:/Users/StephenBlair/Documents/example 

render -s 6 -e 8 -r arnold -rt 1 -preRender %PRE_RENDER_MEL% C:\projects\Support\scenes\_2016\XSI_deformed_logo.mb

There’s also the arnoldExportASS command, if you want to script the export.

maya -batch -file scene.mb -command "arnoldExportAss 
-f "/home/blairs/Desktop/example.ass" -mask 255 -lightLinks 1 -compressed 
 -shadowLinks 2 -cam sideShape;"

[Arnold] [kick] Enabling tiled EXRs


Suppose you have a load of ASS files that were exported with the Tiled option disabled. How could you re-enable the Tiled option without re-exporting the ASS files?

With the kick -set flag, that’s how:

kick -set display_exr.tiled on

That will set the tiled parameter for all EXR driver nodes in the ASS file.

If you want to set the flag for a specific driver node, you need to know the driver node name.

kick -set defaultArnoldDriver@driver_exr.RGBA.tiled on

That sets tiled for the driver_exr node named defaultArnoldDriver@driver_exr.RGBA.

Portable ASS files with relative paths and the Texture Search Path


You can make your ASS files portable across different platforms by using relative paths and the texture search path. For example, if all textures are specified by relative paths like “textures/noicon.tx”, then you just have to set options.texture_searchpath to specify the location of the textures folder.

For example

kick -set options.texture_searchpath //server/project/ -dp -dw example.ass

Or if the texture search path is set to an environment variable

export ARNOLD_TEXTURE_PATH=//server/project
./kick example.ass

To use relative paths for texture file names in nodes like MayaFile, aiImage, aiPhotometricLight, and aiSkydomeLight, you just need to do the following:

  • Put a relative path in the file name box (for example, in Photometry File box of an aiPhotometricLight node, or the Image Name box of an aiImage node)
  • Set the Texture Search Path (Render Settings > System > Search Paths)
  • Clear the Absolute Texture Paths check box

You can put multiple locations, using either : or ; to separate the paths (Arnold supports both separators on all platforms: OSX, Linux, and Windows)

You can use environment variables by putting the environment variable name in square brackets. For example:

"[ARNOLD_TEXTURE_PATH]:C:/Assets/IES/;C:/maya/projects/Support/sourceimages"

Forward slashes work on all platforms.

MtoA appends the current project’s sourceimages folder to the texture search path.

Creating a polymesh with the Arnold Python api


polymesh
Here’s a snippet that shows how to create a simple four-polygon polymesh node with the Arnold Python API.

n = AiNode( "polymesh" )
AiNodeSetStr( n, "name", "grid" )

nsides = [4, 4, 5, 6]
AiNodeSetArray( n, "nsides", AiArrayConvert(len(nsides), 1, AI_TYPE_UINT, (c_uint*len(nsides))(*nsides) ) )

vidxs = [0, 1, 4, 3, 1, 2, 5, 4, 3, 4, 7, 6, 9, 4, 5, 11, 8, 10, 7]
AiNodeSetArray( n, "vidxs", AiArrayConvert(len(vidxs), 1, AI_TYPE_UINT, (c_uint*len(vidxs))(*vidxs) ) )

nidxs = [0, 1, 2, 3, 1, 4, 5, 2, 3, 2, 6, 7, 8, 2, 5, 9, 10, 11, 6]
AiNodeSetArray( n, "nidxs", AiArrayConvert(len(nidxs), 1, AI_TYPE_UINT, (c_uint*len(nidxs))(*nidxs) ) )

vlist = [-1, 0, -1, -1, 0, 0, -1, 0, 1, -0.197835326, 0, -0.742445886, 0, 0, 0, 0, 0, 1, 0.802164674, 0, -0.742445886, 1, 0, 0, 1, 0, 1, 0.270379633, 0, -1.21302056, 1, 0, 0.508926511, 0.496316135, 0, 1]
AiNodeSetArray( n, "vlist", AiArrayConvert(len(vlist), 1, AI_TYPE_FLOAT, (c_float*len(vlist))(*vlist) ) )

nlist = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
AiNodeSetArray( n, "nlist", AiArrayConvert(len(nlist), 1, AI_TYPE_FLOAT, (c_float*len(nlist))(*nlist) ) )

m = AtMatrix( 	1, 0, 0, 0,
		0, 1, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1 )

am = AiArrayAllocate(1, 1, AI_TYPE_MATRIX)
AiArraySetMtx( am, 0, m )

AiNodeSetArray( n, "matrix", am  )

AiNodeSetBool( n, "smoothing", True )

AiNodeSetByte(n, "visibility", 255 )

# Assign a shader to the polymesh node
u = AiNode( "utility" )
AiNodeSetStr( u, "name", "aiUtility1" )

AiNodeSetPtr( n, "shader", u )

And here’s the resulting node in the ASS file:

polymesh
{
 name grid
 nsides 4 1 UINT
4 4 5 6
 vidxs 19 1 UINT
  0 1 4 3 1 2 5 4 3 4 7 6 9 4 5 11 8 10 7
 nidxs 19 1 UINT
  0 1 2 3 1 4 5 2 3 2 6 7 8 2 5 9 10 11 6
 vlist 12 1 POINT
  -1 0 -1 -1 0 0 -1 0 1 -0.197835326 0 -0.742445886 0 0 0 0 0 1 0.802164674 0 -0.742445886 1 0 0
  1 0 1 0.270379633 0 -1.21302056 1 0 0.508926511 0.496316135 0 1
 nlist 12 1 VECTOR
  0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0
 smoothing on
 visibility 255
 matrix
 1 0 0 0
 0 1 0 0
 0 0 1 0
 0 0 0 1
 shader "aiUtility1"
}

[Arnold] [Python] Changing Arnold options in Python


The global render settings are stored in the options node, which you can get with AiUniverseGetOptions(). If the universe isn’t active (you are not inside an AiBegin() / AiEnd() block so the scene doesn’t exist yet), AiUniverseGetOptions() returns None.

Once you have the options node, you can load options from an ASS file, or you can update it with the node parameter setters such as AiNodeSetInt(). The way kick, and pykick, work is that they load the ASS file first, with its options, and then update the options node with the values from the command line.

from arnold import *
import os

AiBegin()

AiMsgSetConsoleFlags(AI_LOG_ALL)

# Get the default options
options = AiUniverseGetOptions()

AiLoadPlugins( os.getenv( 'ARNOLD_PLUGIN_PATH' ) )

AiASSLoad("C:/Users/Support/project/scenes/test_640x480.ass", AI_NODE_ALL)

# Render using options loaded from the ASS file
AiRender()

# Change options and render with the changes
AiNodeSetInt(options, 'xres', 320)
AiRender()

# Load options and use them to render
AiASSLoad("C:/Users/Support/project/scenes/test_960x540.ass.gz", AI_NODE_OPTIONS)
AiRender()

AiEnd()

[kick] [ass] reading from stdin


Some customers have reported a problem using a render manager (Muster, Tractor, Deadline) to render jobs with kick, typically via a wrapper script. The problem is that kick tries to read from STDIN instead of loading the specified ASS file. In the log, you’d see this:

00:00:00     0MB         | [ass] reading from stdin ...

A workaround is to add the -nstdin flag (Ignore input from stdin) to the kick command line.