Bypassing Nodes During Renders
As a Nuke script gets larger and starts to contain quite a few nodes, the processing of the script may take longer to respond. This is especially the case with nodes that require more processing power for their calculations, such as GPU accelerated node, and can cause lagging when working in the script. Some examples of heavy processing nodes that may introduce slowdowns when using Nuke include: BlinkScript, Convolve, Denoise, Defocus, Kronos, MotionBlur, OFlow, VectorGenerator, and ZDefocus.
For such scripts where working becomes difficult and lagging occurs, there is a handy $gui expression operator that can be used to disable user interface (GUI) processing. The $gui operator in expressions returns either 1 or 0 as result:
• 1 is returned when the node is calculated through the GUI.
• 0 is returned at render time, when the node is not being processed by the GUI.
The standard way to add this into a node is through an expression. Functionality-wise, it acts similar to a Switch node but is driven by whether the GUI is being used or not, which makes it autonomous.
Note: These nodes are GPU accelerated nodes and if you have a fast graphics card, the $gui operator in expressions might not be needed. However, if you are experiencing lagging, using $gui in expressions in conjunction with your GPU acceleration may help.
The most common uses for the $gui operator in Nuke are: The Switch Method, The Disable Method, and The Selective Variation Method.
The Switch Method
The Switch method is the most common way of using $gui in expressions. Unlike the other methods, it allows you do disable the Switch node and turn off the expression when not needed.
1. | Create a Switch node after the processor heavy node. |
2. | Right-click on the Switch node's which control and then select Add expression... |
3. | In the expression box type $gui. You should see the result displayed as 1 since the node is processed within the Nuke GUI. |
4. | Connect the 0 input to the processor heavy node (in this example a MotionBlur node with 20 samples). |
5. | Connect the 1 input to the node tree before the processor heavy node (in this example a Transform node). |
6. | Playback the Viewer frames through the GUI and you will see the processing done faster since it bypasses the MotionBlur node and not display the blur results applied to the final image. |
7. | To process the MotionBlur and see the final result, render to disk using Render in background or the Frame Server. This uses an external process outside of the Nuke GUI and should not slowdown the script manipulation in the meantime. |
Note: If you don't render in the background or use the Frame Server, the render uses the same process as the Nuke GUI and will not work as expected.
8. | Once rendered, the motion blurred result is processed and displayed. |
The Disable Method
The Disable method uses the disable option in the node's settings, rather than using the Switch node. This is a bit cleaner with less nodes, but more difficult to turn off the expression.
Note: Using the Disable method means you must delete the expression to view the node processing results in the GUI, it completely bypasses the node.
1. | Right-click the MotionBlur's disable control select Add expression... |
2. | Type $gui in the Expression control and click OK. |
3. | Play back the Viewer to see that the MotionBlur node processing is bypassed and does not display any blur effect. |
4. | The results of the render are the same as The Switch Method, however, you must remove the expression completely to re-enable the blur effect. |
The Selective Variation Method
The Selective Variation Method uses the $gui operator expression in combination with two other values. This allows setting two independent numeric values that can be assigned to a parameter depending on which mode Nuke is in (either GUI or during rendering in non-GUI), as appose to only an on/off value result. The expression looks like this:
$gui?0:20
0 is the value to use in Nuke GUI mode and 20 the value to use outside GUI mode, during rendering.
Note: Using the Selective Variation method means you must delete the expression to view the node processing results in the GUI, it completely bypasses the node.
1. | In the node (in this example, the MotionBlur node), the expression $gui?0:20 is added and assigned to the Shutter Samples control. This renders 0 samples in the GUI and 20 samples during a background render. |
2. | If you play this through the GUI, you will see that it accesses the MotionBlur node, but the values remain at 0 until rendered using Render in background, when it will use 20 samples. |
3. | The results of the render are the same as The Switch Method. |