Recently, I've been working on comps that required me to use the native Nuke 3D particle system to create a basic simulation to enhance live-action elements in a few shots. I had various particle nodes piping down into a scanline render at the bottom of the comp, before being merged with the background plate. Many compositors are all too familiar in knowing that nodes like the scanline render can easily become like sandbags in your comp. It only takes a few of these nodes to get the machine grinding, especially with high sample counts. The main issue was that when I previewing my work, a low sample count was acceptable to get the gist of what's going on in the shot, but when I sent the render to the farm, I wanted a higher sample count for the final output.
I tried a few different methods to help solve this issue such as creating a NoOp adding a slider knob and expression linking every samples slider in every scanline render node to that NoOp. This quickly got messy with expression lines everywhere and I still had to remember to change the value in the NoOp when I was ready to render. Furthermore, this method assumed that all scanline renders would use the same sample count. If I wanted to have a scanline with a different sample count, I'd have to create a new NoOp, link all the values and remember to change that node too at render time. The project lead saw me struggling with this pile of jank and offered up a much simple solution, the $gui expression.
the good stuff.
This simple TCL expression checks to see if Nuke's GUI is active and returns a boolean value, True if the GUI is active and False if the GUI is not active. When working on the box, the GUI is running and returns True, but when the script goes out to the farm, the GUI is no longer active with a farm license and will return False. This provides an avenue to be able to tell Nuke how to proceed if a shot is being viewed on the box or the farm. We can use an expression in a switch node to swap inputs between a scanline render with low samples and a scanline render with high samples. In the image below you can see the setup I was using for many of the shots on this project. The switch node has the expression '$gui' in the 'which' knob. The switch pipe will be set to 1 when working on my machine because the GUI is active and will return True. This will enable the low sample, faster to preview scanline render. When the shot goes off to the farm, the GUI will no longer be active and the expression will return False and the switch will be set to 0 which enables the high sample scanline render.
This solution is faster to preview and easy to read if another artist picks up the shot. The script automatically swaps inputs at render-time so we don't have to be bothered with increasing the sample count before the shot goes to the farm. Furthermore, this allows us to have unique sample counts for each scanline render node if the shot requires. This TCL snippet is not restricted to just the scanline render node, it can be used in any scenario where the user wants to change values in a node at render-time. I find myself using this method often with any node that contains a 'samples' or similar knob; motion blur, transforms, defocus, vector blur, god rays in addition to the scanline render to name a handful.
Let's get a tiny bit more technical here. We can apply further boolean logic with TCL to swap samples in a node without the need for the switch node. In the expression editor for a knob a TCL 'if' statement will work just fine in setting knob values that check to see if Nuke's GUI is enabled. The syntax would be as such:
Again, with TCL, you can invert the '$gui' expression to get the opposite value using '!$gui'. I find that adding the expression inside the node, as shown above, is a less user intuative solution. If another artist picks up the shot, they may not be able to tell that there is an expression inside the node which could lead to problems when troubleshooting a shot. Nuke scripts are a lot like handwriting, each person has their own unique style but overall your handwriting should be readable to everyone else! Using the switch is a user intuative method with a clear visual language that displays what you've done in your comp to make it work.
I hope this brief write up is helpful. Happy comping!