Search

Week 17.5: How to Set a ShaderFX Setting

Maya's ShaderFX has a lot of names for its options: attribute, setting, property, value.

Exposed attributes can be changed regularly with PyMel, for example: for a ShaderFX material named "MI_Waooer", the attribute name can be found by changing it's value and looking at the script editor for clues.

Then we can do the usual:

pm.PyNode('MI_Waooer').Use_Base_Color.set(True)

For ShaderFX settings, the options above the attributes in the attribute editor, it gets slightly more complicated because we have to use the ShaderFX commands, which are kind of undocumented, and its all in MEL. Luckily GitHub user tm8r created some kind of documentation.

If you are reading over the documentation and wondering, WTH is a "node_uniqueID"??? Fret not, press the big "Open ShaderFX" button in the attribute editor after selecting the ShaderFX material. Then go to the settings menu at the top of the window, and press "Show Node ID", voila, unique node ID's everywhere. Note, ShaderFX graph's node ID is saved with the scene and is not discarded unlike Maya's UUIDs.











In this example, I'll be changing the bool's Value property to True. Note the unique ID of my bool node is 1291











To figure out the name of the property we want to set, list all the properties a node has with the following command and find the proper name

shaderfx -sfxnode MATERIAL_NAME -listProperties UNIQUE_NODE_ID;
shaderfx -sfxnode "MI_Waooer" -listProperties 1291;

In my case, I get this long list of properties:

helpaction name width note socketdefaultvalue socketswizzlevalue version posx posy collapsed previewswatch group activesocket activesocketlabel compoundassignment hasbeenedited value exposesetting uiorder uigroup

Now, that I know the property name is called "value", and that my property is of type bool (not to be confused with the node type), I can execute the following command. The key flag is -edit_bool. Make sure to browse the documentation for the appropriate type of flag based on the property type

shaderfx -sfxnode MATERIAL_NAME -edit_bool UNIQUE_NODE_ID PROPERTY_NAME DESIRED_VALUE;
shaderfx -sfxnode "MI_Waooer" -edit_bool 1291 "value" false;

In case you are wondering about the my personal use for setting a property, the Norrsken PBR shader has a setting called Opacity driven by a bool that sets whether a diffuse map has clipping or blending opacity.









If your diffuse map does not have any alpha and is not meant to be transparent, it should be left as "Clipping". However, if the diffuse map does have alpha and is meant to be transparent, this setting needs to be set to "Blending". Below is a quick way of testing for alpha values and setting the property.

# file nodes have a nice attribute that tests whether a file has alpha or not
opacity_tester = pm.createNode('file', name='opacityTest')
opacity_tester.fileTextureName.set(texture_path)

# set opacity blending mode to blending instead of clipping if file has alpha
if opacity_tester.fileHasAlpha.get():
    pm.mel.eval('shaderfx -sfxnode "{}" -edit_bool 1291 "value" false;'.format(material.nodeName()))

pm.delete(opacity_tester)