Expressions

From RMIT Visual Effects
Jump to: navigation, search

Nuke is a very open application, which can be easily extended by the user. An example is the ease by which values in one node can be made to drive those of another. This is done by the use of expressions. One of the advantages of this that it can make complex animations easy to master, enabling many node parameters to be driven from one 'master' node.

How to copy and link values from one node to another

Below is shown how to copy the values from one node to another. This is done by 'Option' dragging the little icon that looks like a graph to its destination parameter. This will only copy the value from that particular frame, with no animation.

Copying a value from one node to another by 'option' dragging it.

To link the animation from one node to another we 'Command' drag it. This will automatically place one node in a slave relax hip to another. We can review this relationship 'under the hood' by 'Right' clicking on the value and selecting 'Edit expression'. A simple expression can be seen, the syntax of which is fairly obvious. In this case, the parameter 'Multiply3' is being driven by the parent 'Multiply3'.

An expression that references the values of one parameter to drive another.

This simple expression can be edited and elaborated on. In the case of the expression above it was changed from: parent:Multiply1.value to -Multiply1.value. This simple maths inverts the child value. The effect of this linkage can be seen in the code snippet below. The color operations on the (child) square in the middle of the rectangle is always in opposition to the (parent) background. If you look in the Curve Editor you will notice that the two curves mirror each other, also that the slave value can not be directly edited. However, if you change the master value you will notice that the slave will update. Code snippet below:

Press 'Expand' and select and copy everything below this line, then paste into the Nuke node graph.

set cut_paste_input [stack 0]
version 9.0 v7
Constant {
 inputs 0
 channels rgb
 color 0.5
 name Constant7
 selected true
 xpos 2047
 ypos -3316
}
set Nafdca370 [stack 0]
Add {
 value {{-Add_MASTER.value}}
 name Add_SLAVE
 selected true
 xpos 1922
 ypos -3129
}
push $Nafdca370
Add {
 value 0.5
 name Add_MASTER
 selected true
 xpos 2142
 ypos -3134
}
CopyRectangle {
 inputs 2
 area {512 389 1536 1167}
 name CopyRectangle6
 selected true
 xpos 2030
 ypos -3016
}
Write {
 name Write2
 selected true
 xpos 2030
 ypos -2984
}
StickyNote {
 inputs 0
 name StickyNote4
 label "Read from the 'Write' node and then open 'Add_MASTER'\n\nChange its value and watch how Add_SLAVE is the mirror \nof Add_MASTER. This is being driven by the simple expression:\n'-Add_MASTER.value'"
 selected true
 xpos 2174
 ypos -3238
}

Adding knobs

The problem with using expressions in the manner just described is that they are bothersome to edit. To address this we can add a new knob to a node to drive a key value of the expression. This we can do within a node (right click anywhere on the node and select 'Manage user knobs' ) or we can do it on a brand new node. Such a node starts out life as a 'NoOp' node. Here we can add parameters that drive other nodes using expressions. Here's how:

  1. Create a Multiply node.
  2. Make a NoOp node (its a kind of 'blank' node).
  3. Rename it 'Master'
  4. Right click on its tab and select 'Manage user knobs'.
  5. From the resulting dialogue box select 'Add / Floating Point Slider'. Edit it in the following way:
    • Name: 'moderator'
    • Label: 'Moderator' (a label can contain upper case letters and spaces)
    • Tooltip: 'This moderates you fool!'
    • Minumum: '-1'
    • Maximum: '1'
  6. Click done.
  7. Now right click in the 'value' parameter of the Multiply and write: =value*Master.moderator

You can now control the value of the Multiply, using the sliding value knob of 'Master'.

The snippet below is a simple example of an expression being driven by a linked value, via a NoOp node.

Press 'Expand' and select and copy everything below this line, then paste into the Nuke node graph.

set cut_paste_input [stack 0]
version 9.0 v7
Constant {
 inputs 0
 channels rgb
 color 0.5
 name Constant4
 selected true
 xpos 3806
 ypos -3008
}
set Nd1654a00 [stack 0]
Dot {
 name Dot9
 label "\nThrough a linked expression, this Add node\nis the inverse of the other Add node. "
 note_font_color 0x55ffbfff
 selected true
 xpos 3722
 ypos -2852
}
Add {
 value {{-Add8.value}}
 mix 0
 name Add7
 selected true
 xpos 3688
 ypos -2827
}
push $Nd1654a00
Dot {
 name Dot8
 label "This Add is being driven by a random expression. \nA key value of that expression is being driven, in \nturn, by the Master node (an adapted NoOp node)."
 note_font_color 0x55ffbfff
 selected true
 xpos 4028
 ypos -2847
}
Add {
 value {{"fBm(frame*Master1.moderator, (20), 0, 5.3, 1.16, 0.5)*2" 0.4756122231 x5 -0.517770648 0.5 -0.4872667789 x18 0.475839287 -0.4822243452 x25 0.465211302 -0.5001246929 x34 0.4756122231 x40 -0.4102654457 x56 0.4723314047 x64 -0.5041589737 x75 0.4347740412 x83 -0.4853801727}}
 name Add8
 selected true
 xpos 3994
 ypos -2821
}
CopyRectangle {
 inputs 2
 area {512 389 1536 1167}
 name CopyRectangle4
 selected true
 xpos 3799
 ypos -2705
}
Constant {
 inputs 0
 channels rgb
 color 0.5
 name Constant5
 selected true
 xpos 3068
 ypos -3053
}
set Nd166bb20 [stack 0]
Dot {
 name Dot6
 label "\nThrough a linked expression, this Add node\nis the inverse of the other Add node. "
 note_font_color 0x55ffbfff
 selected true
 xpos 2946
 ypos -2899
}
Add {
 value {{-Add10.value}}
 name Add9
 note_font_color 0xff
 selected true
 xpos 2912
 ypos -2871
}
push $Nd166bb20
Dot {
 name Dot7
 label "This Add is being driven by a random expression."
 note_font_color 0x55ffbfff
 selected true
 xpos 3259
 ypos -2903
}
Add {
 value {{"fBm(frame*0.15, (20), 0, 5.3, 1.16, 0.5)*2" x1 0.383574605 x5 -0.517770648 x10 0.5 -0.4872667789 x18 0.475839287 -0.4822243452 x25 0.465211302 -0.5001246929 x34 0.4756122231 x40 -0.4102654457 x56 0.4723314047 x64 -0.5041589737 x75 0.4347740412 x83 -0.4306218624 x100 0.3986934423}}
 name Add10
 note_font_color 0xff
 selected true
 xpos 3229
 ypos -2879
}
CopyRectangle {
 inputs 2
 area {512 389 1536 1167}
 name CopyRectangle5
 selected true
 xpos 3058
 ypos -2749
}
Viewer {
 frame_range 1-100
 name Viewer3
 selected true
 xpos 3109
 ypos -2660
}
push $cut_paste_input
Dot {
 name Dot4
 label "\n\nThe lightness of the small rectangle is being driven by a random expression\nby 'Add1'. The lightness of the surrounding is the invert of this. To see how this \nworks do this:\n\n1)  Double-click the node 'Add2' and right click on the 'value' parameter (in blue)\n2)  From the contextual menu, select 'edit expression'\n3)  You will see that the 'value' parameter is being driven by \nthis expression: '-Add1.value'             \n\nThis means that... \n(a) The 'add' parameter of 'Add1' is being referenced.\n(b) This value is being inverted (the minus sign). \n\n"
 note_font_color 0x55ffbfff
 selected true
 xpos 3257
 ypos -3019
}
NoOp {
 inputs 0
 name Master1
 tile_color 0xff0000ff
 selected true
 xpos 3921
 ypos -2974
 addUserKnob {20 User}
 addUserKnob {7 moderator l Moderator R 0 0.3}
 moderator 0.134
}
Dot {
 inputs 0
 name Dot5
 label "\n\nThis arrangement is the same as the preceding one..,,.\nexcept a key value of the expression is being driven \nby the 'Master' node. \n"
 note_font_color 0x55ffbfff
 selected true
 xpos 4074
 ypos -2949
}
StickyNote {
 inputs 0
 name StickyNote2
 label Animated!
 note_font_size 90
 selected true
 xpos 3443
 ypos -3329
}