Q100349: Using $gui in expressions to bypass processor heavy nodes when working within the GUI

Follow

SUMMARY

As a Nuke script gets larger and starts to contain quite a few nodes, the processing of the script will start to take longer to respond. This is especially the case with nodes that require more processing power for their calculations, and can cause lagging when working in the script. 

For such scripts where working becomes difficult and lagging occurs, there is a handy expression operator that can be used to disable the GUI processing. This operator is known as '$gui' and this article will explain how it works and the node expression methods you can use to improve performance. 

 

MORE INFORMATION

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

This makes it quite handy, especially for rendering as there are ways to render outside of a Nuke's GUI environment.

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.

Some examples of heavy processing nodes that may introduce slowdowns when using the Nuke GUI include: BlinkScript, Convolve, Denoise, Defocus, Kronos, MotionBlur, OFlow, VectorGenerator, ZDefocus, etc. 

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.

 

HOW TO USE

The '$gui' operator can be used in a script in several different ways. Below are the most commonly used methods:

NOTE: There is also a script attached to this article with these three methods to allow you to test and apply this method in your own scripts. You can find this script at the bottom of this article.

 

Switch Method

The Switch method is the most common way of using the '$gui' operator in expressions. Unlike the other methods, it allows you do disable the Switch node and turn off the expression when not needed.

This can be setup by following the below steps:

1. Create a 'Switch' node after the processor heavy node.

2. Right click on the 'Switch' node's 'which' knob value and 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. 


expression_window.PNG

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. 

switch.PNG

7. To process the MotionBlur and see the final result render to disk using 'Render in Background' or using the 'Frame Server' in Nuke 11. This will use an external process outside of the Nuke GUI and should not slowdown the script manipulation in the meantime.


renderbg.PNG


NOTE: If you don't render in the background or via the Frame Server then the render will use the same process as the Nuke GUI and will not work as expected.

8. Once rendered, you will get the motion blurred result processed and displayed like: 

Switch.0005.jpg

 

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 (as you will have to remove the expression to see the effect).

1. In the MotionBlur node's 'disable' option, add an expression by right clicking on the knob and selecting 'Add expression...'. 

Enter in the expression box type '$gui'

disablemethod.PNG

2. If you play this in the Viewer with the Nuke GUI, you will see that it bypasses the MotionBlur node processing and does not display any blur effect. 

disablemethod_flow.PNG

3. The results of the render will be the same as the 'Switch' method above, however, you will have to remove the expression completely to re-enable the blur effect. 

 

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' being the value to use in Nuke GUI mode and '20' the value to use outside GUI mode, during rendering.

1. In the node (in this example I am using the MotionBlur node), I have added the expression '$gui?0:20' and have assigned this expression to the 'Shutter Samples' knob. This will give me '0' samples in the GUI and '20' samples during a render.

 

motionmethod.PNG

2. If you play this through the GUI, you will see that it accesses the MotionBlur node, but the values will remain at 0 until rendered via 'Render in Background' so outside GUI mode, when it will use 20 samples.

selective_variation.PNG

3. The results of the render will be the same as the 'Switch' method above.

 

LIMITATIONS

There are several limitations to this technique that need to be mentioned:

1. You need to render outside of the GUI for this to work, which means you will need to 'Render in Background' or render via the 'Frame Server' (Nuke 11 and up)

2. With the Disable and Selective Variation methods, you will have to delete the expression to view the node processing results in the GUI, it completely bypasses the node. 

Was this article helpful?
0 out of 0 found this helpful

Comments