[Maya][Python] Creating ShaderFx Networks



I´m trying to create a shaderFx network with python, and there´s no documentation, or I can´t find it.
I´m able to create a shaderFx shader and assign to a geometry but I don´t know how to access to the nodes like TextureMap, MultOp, LerpOp, … and do the connections between the nodes.

Anyone has some experience or examples to look at?
Thanks in advice! :slight_smile:


It’s pretty gnarly. I wrote a module precisely for dealing with how nasty it is: https://github.com/theodox/sfx

Even if you don’t end up using it, the comments in the code will give you an idea of how the (mostly undocumented) commands are set up.


Cool! Thanks Theodox! Really useful! I´ll have a look :slight_smile:


Hi again.
I´m trying to create a shaderFx shader from scratch with your your module @Theodox and I´m not able to do the connections or find the appropiate input name for a textureMap.
Is there a way to know the inputs/outputs for a specific node like a mult or textureMap?

This is what I have so far.
I can create all the nodes I need, but when It comes to connect the nodes I can not connect the vertexcolor.rgb to the baseTextureNode textureColor Node.
Any suggestions?

I really appreciate it!
Thanks :slight_smile:

new_network = SFXNetwork.create('ShaderName')
verteColorNode = new_network.add(sfxnodes.VertexColor, 'VertexColor')
baseTextureNode = new_network.add(sfxnodes.TextureMap, 'BaseTexture')
blendTextureNode = new_network.add(sfxnodes.TextureMap, 'BlendTexture')

mult01Node = new_network.add(sfxnodes.Multiply, 'Mult01')
mult02Node = new_network.add(sfxnodes.Multiply, 'Mult02')

# Connect Nodes
new_network.connect(verteColorNode, verteColorNode.outputs.rgb, mult01Node, mult01Node.inputs.value)


I managed to do the connection with this :slight_smile:
new_network.connect(verteColorNode.outputs.rgb, ((mult01Node.inputs.value)[0], 0))
But I think it could be done in another nicer way.

Also, I want to create a LerpOp Node, but I can´t. Is not yet implemented?
I was looking into the sfnodes.py and there´s no LerpOp class.
I´m trying to implement the LerpOp, but I can´t figure out the ID for the LerpOp, any suggestions to get the correct ID? :slight_smile:

Thanks again!


I replied on the slack, but you hit the basics. connect() really needs 4 numbers:

  • the node index for the first node
  • the plug index for the output you want, the node index for the
  • the node index for the second node
  • the plug index for the second plug

In this case the API name for the multiply node’s inputs is “value” for both of them ( I think this is a change that crept into a 2016 service pack) . It means that both of the inputs report the same index, so only one of them connects with the default method. You can do it like this:

new_network.connect(vertexColorNode.outputs.rgb, mult_node.index, 0)

To get the id’s for the nodes, you need a list of the UI names for all the nodes. I got the original by just copying them down from the UI – it looks like lerp is called “Linear Interpolate Mix”. You’d add that to the list of node names in sfxnodes.py, then do this:

  1. make a dummy shader
  2. call SFXNodeType.generate_class_definitions() with the shader and the updated list of names as an argument

That should spit out the the text of all the node classes, which you should merge with the existing definitions in sfxnodes.py