Hello.
I'm trying to write a python script that fixes the unity issues related to smoothness and metallic.
I wrote a script that finds the metallic and roughness outputs, gets the connections to the left and then connects those nodes to a bunch of new nodes (invert, channel shuffle, a new output).
This works really well when the nodes the outputs are connected to are simple things, like a levels, or a blur and so on. Now, I've stumbled upon a case where the node on the left hand of the connection has multiple outputs (in fact, it's a whole material).
The issue is that since I don't specify what output to connect to, they always get connected to the first one (a diffuse in this case). Is there any way to know what output from a node a connection is made to? I might not be understanding this so well since I'm a bit new to python but I'm "fluent" in c++ and other more normal languages.
Here's the code that handles this roughness/metallic->metalSmoothenss issue:
#Get Metallic and RoughnessNodes
metallicOutput = graph.getGraphOutputNode(aOutputIdentifier = 'metallic')
metallicNodeUid = graph.getNode(metallicOutput.mUID).mConnections[0].getConnectedNodeUID()
metallicNode = graph.getNode(metallicNodeUid)
roughnessOutput = graph.getGraphOutputNode(aOutputIdentifier = 'roughness')
roughnessNodeUid = graph.getNode(roughnessOutput.mUID).mConnections[0].getConnectedNodeUID()
roughnessNode = graph.getNode(roughnessNodeUid)
#Create MetallicSmoothness output
invertedRoughness = graph.createCompFilterNode(aFilter = pysbs.sbsenum.FilterEnum.LEVELS,
aParameters = {
pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_LOW : '0.0 0.0 0.0 0.0',
pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_HIGH: '1.0 1.0 1.0 1.0',
pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_MID: '0.5 0.5 0.5 0.5',
pysbs.sbsenum.CompNodeParamEnum.LEVEL_OUT_LOW: '1.0 1.0 1.0 1.0',
pysbs.sbsenum.CompNodeParamEnum.LEVEL_OUT_HIGH:'0.0 0.0 0.0 0.0',
pysbs.sbsenum.CompNodeParamEnum.CLAMP_IN_TERM: '1'
}
)
graph.connectNodes(aLeftNode = roughnessNodeUid, aRightNode = invertedRoughness)
metallicSmoothMerge = graph.createCompFilterNode(aFilter = pysbs.sbsenum.FilterEnum.SHUFFLE,
aParameters = {
pysbs.sbsenum.CompNodeParamEnum.CHANNEL_RED: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
pysbs.sbsenum.CompNodeParamEnum.CHANNEL_GREEN: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
pysbs.sbsenum.CompNodeParamEnum.CHANNEL_BLUE: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
pysbs.sbsenum.CompNodeParamEnum.CHANNEL_ALPHA: pysbs.sbsenum.ChannelShuffleEnum.INPUT2_RED
})
graph.connectNodes(aLeftNode = metallicNodeUid, aRightNode = metallicSmoothMerge, aRightNodeInput = pysbs.sbsenum.InputEnum.INPUT1)
graph.connectNodes(aLeftNode = invertedRoughness, aRightNode = metallicSmoothMerge, aRightNodeInput = pysbs.sbsenum.InputEnum.INPUT2)
outMetallicSmoothness = graph.createOutputNode(aIdentifier = 'metallicSmoothness',
aUsages = {pysbs.sbsenum.UsageEnum.ANY: pysbs.sbsenum.ComponentsEnum.RGBA})
graph.deleteNode(graph.getNode(metallicOutput.mUID))
graph.deleteNode(graph.getNode(roughnessOutput.mUID))
If anyone of you could help me out with this, I'd greatly appreciate it.
Also, on a more unrelated note, when using sbsrender it would be great if there would be an option to invert the normals(only the ones in the output since others might be used for curvature sobel or something). So far I've had to do this from within Unity and it's rather tedious to figure out how the TextureImporter works.
Regards,
Lorin