A Simple Nuke Expression Tutorial

This is a very basic example of what you can do with an expression in Nuke. If you already use expressions regularly then this is probably too basic for you but if you have never used expressions before I hope this shows that even the simplest ones can be very useful and can be built on.

You can download a copy of the script I created these examples in here.

I decided to write this post after I answered a question on VFX Talk. The original poster wanted to progressively add jitter to an element in their shot.

One of the simplest ways to add jitter is to create a transform node and use the random function in an expression for the translate values. To do this click on the animation menu (the little graph icon) next to the translate properties and choose ‘edit expression’. In the box that pops up type:


in both the x and y properties and click ok. Whenever there is an expression somewhere in a node a little green circle appears on the corner of the node.

The random function will generate a random number between 0 and 1 on each frame. On its own this will give you a very fine jitter to the element, like this:

To increase the size of the jitter you can simply multiply the result of the random function in the expression. Choose ‘edit expression’ again and change the expression to this:


This will take the result of the random function and multiply it by 10 to give you a result like this:

With this setup you have to edit the expression manually each time you want to change the amount of jitter. A better way to set this up is to create a control knob on the node and hook that up to the expression. In this case I’m going to add a slider to control the size of the jitter.

Right click anywhere on the properties panel of the transform node and choose ‘manage user knobs’. Click ‘add’ and choose ‘floating point slider’ from the dropdown. A new dialogue box will open. This is where we set up the properties of the slider we are about to create.

Firstly we need to name the slider. This isn’t the name we will see in the properties panel but the name we will use in any expressions that reference the slider. Expressions are case sensitive and don’t like spaces so it’s best to keep everything lowercase and use underscores to make life easier. In this example I’m going to call the slider ‘jitter_multiply’.

In the label box you can decide what text will appear next to the slider to tell the user what it does. This doesn’t have to conform to the same rules as the name so you can call it whatever you like. I went for “Jitter Multiply”. The tool tip option lets you add text that will appear when you hover your cursor over the control – in this case I left it empty but if you are creating a tool other artists will use I suggest adding a description. At the bottom you can set the minimum and maximum values of the slider. I set mine to 0-10.

Click ok in this dialogue box and then done in the previous box and you will see there is a new tab in your transform node’s properties panel called ‘user’, which contains the slider you have just created. You can change any of the slider settings by going back to the ‘manage user knobs’ panel, selecting the slider in the list and choosing ‘edit’.

Right now the slider doesn’t do anything except look pretty. We need to hook the expression up to it.

Go back to the expression in the translate properties. Now instead of multiplying the random number by 10 we want to multiply it by whatever the slider is set to. We do that by changing the expression to:


Remember that anything multiplied by 0 is 0 so if you set the slider to 0 you are effectively turning off the jitter effect. Anything multiplied by 1 stays the same so if you set the slider to 1 you are basically turning the effect on but not adjusting it.

This slider acts like any other slider in Nuke, which means you can keyframe it. This allows you to progressively add jitter to the element over time like this:

You can even reference the values in the slider from other nodes, but then you have to point to the node the slider is in, like this:


where Transform3 is the name of the node.

This is a very simple example of what you can do with expression but I thought it was something that would be easy to build on and is useful in all sorts of situations.