# Expression

Allows you to apply complex mathematical formulas to a channel’s values using C-like syntax expressions. If necessary, you can apply different expressions to different sets of channels.

x or y is the pixel coordinate. If the input is a proxy image, then these are scaled and translated to the coordinate that would be in the full size image.

cx and cy can provide a more useful coordinate system. In this system 0,0 is the center of the picture.

-1,0 is the center of the left edge, 1,0, is the center of the right edge. 1,1 is a point 45 degrees up from the origin on the right edge (outside the top of the picture if the aspect ratio is greater than 1).

You can refer to any input channel by name, for example r for the red channel.

You can refer to any control on any node by its name. For example, Blur1.size returns the size of the blur. You can also evaluate animated controls, for example Blur1.size(t).

A blank expression is the same as zero.

All math is done with 32-bit floating point numbers.

# Inputs and Controls

 Connection Type Connection Name Function Input unnamed The image sequence to which you want to apply expressions. mask An optional image to use as a mask. By default, the expressions are limited to the non-black areas of the mask. At first, the mask input appears as triangle on the right side of the node, but when you drag it, it turns into an arrow labeled mask. If you cannot see the mask input, ensure that the mask control is disabled or set to none.

The following functions are supported:

Function

Purpose

Operator Usage

Related Functions

abs (x)

Returns the absolute value of a floating-point number x.

x

acos (x)

Calculates the arc cosine of x; that is the value whose cosine is x.

If x is less than -1 or greater 1, acos returns nan (not a number)

asin (x)

Calculates the arc sine of x; that is the value whose sine is x.

If x is less than -1 or greater 1, asin returns nan (not a number)

atan (x)

Calculates the arc tangent of x; that is the value whose tangent is x. The return value will be between -PI/2 and PI/2.

x

See also: tan, tanh, acos, asin, atan2.

atan2 (x, y)

Calculates the arc tangent of the two variables x and y. This function is useful to calculate the angle between two vectors.

x, y

See also: sin, cos, tan, asin, acos, atan, hypot.

ceil (x)

Round x up to the nearest integer.

x

clamp (x, min, max)

Return x clamped to the min and max values specified.

x, min, max

clamp (x)

Return x clamped to [0.0 ... 1.0].

x

cos (x)

Returns the cosine of x.

cosh (x)

Returns the hyperbolic cosine of x, which is defined mathematically as:
(exp(x) + exp(-x)) / 2.

x

degrees (x)

Convert the angle x from radians into degrees.

x

exp (x)

Returns the value of e (the base of natural logarithms) raised to the power of x.

x

exponent (x)

Exponent of x.

x

fBm (x, y, z, octaves, lacunarity, gain)

Fractional Brownian Motion. This is the sum of octave calls to noise(). The input point for each is multiplied by pow(lacunarity,i) and the result is multiplied by pow(gain,i). For normal use, lacunarity should be greater than 1 and gain should be less than 1.

x, y, z, octaves, lacunarity, gain

fabs (x)

Returns the absolute value of the floating-point number x.

x

false ()

Always returns 0.

none

floor (x)

Round x down to the nearest integer.

x

fmod (x, y)

Computes the remainder of dividing x by y. The return value is x - n y, where n is the quotient of x / y, rounded towards zero to an integer.

x, y

frame ()

Return the current frame number.

none

from_byte (color component)

Converts an sRGB pixel value to a linear value.

color_component

from_rec709 (color component)

Converts a rec709 byte value to a linear brightness.

color_component

from_sRGB (color component)

Converts an sRGB pixel value to a linear value.

color_component

hypot (x, y)

Returns the sqrt(x*x + y*y). This is the length of the hypotenuse of a right-angle triangle with sides of length x and y.

x, y

int (x)

Round x to the nearest integer not larger in absolute value.

x

ldexp (x, exp)

Returns the result of multiplying the floating-point number x by 2 raised to the power exp.

x, exp

lerp (a, b, x)

Returns a point on the line f(x) where f(0)==a and f(1)==b.

Matches the lerp function in other shading languages.

a, b, x

log (x)

Returns the natural logarithm of x.

x

log10 (x)

Returns the base-10 logarithm of x.

x

logb (x)

Same as exponent().

x

mantissa (x)

Returns the normalized fraction. If the argument x is not zero, the normalized fraction is x times a power of two, and is always in the range 1/2 (inclusive) to 1 (exclusive). If x is zero, then the normalized fraction is zero and exponent() returns zero.

x

max (x, y, ... )

Return the greatest of all values.

x, y, (...)

min (x, y, ... )

Return the smallest of all values.

x, y, (...)

mix (a, b, x)

Same as lerp().

a, b, x

noise (x, y, z)

Creates a 3D Perlin noise value - a signed range centered on zero. The absolute maximum range is from -1.0 to 1.0.

This produces zero at all integers, so you should rotate the coordinates somewhat (add a fraction of y and z to x, etc.) if you want to use this for random number generation.

x, optional y, optional z

pi ()

Returns the value for pi (3.141592654...).

none

none

pow (x, y)

Returns the value of x raised to the power of y.

x, y

pow2 (x)

Returns the value of x raised to the power of 2.

x, y

Convert the angle x from degrees into radians.

x

random (x, y, z)

Creates a pseudo random value between 0 and 1 - it always generates the same value for the same x, y and z.

Calling random with no arguments creates a different value on every invocation.

optional x, optional y, optional z

rint (x)

Round x to the nearest integer.

x

sin (x)

Returns the sine of x.

sinh (x)

Returns the hyperbolic sine of x, which is defined mathematically as:
(exp(x) - exp(-x)) / 2.

x

smoothstep (a, b, x)

Returns 0 if x is less than a, returns 1 if x is greater or equal to b, returns a smooth cubic interpolation otherwise.

Matches the smoothstep function in other shading languages.

a, b, x

sqrt (x)

Returns the non-negative square root of x.

x

step (a, x)

Returns 0 if x is less than a, returns 1 otherwise.

Matches the step function other shading languages.

a, x

tan (x)

Returns the tangent of x.

See also: atan, cos, sin, tanh, atan2

tanh (x)

Returns the hyperbolic tangent of x, which is defined mathematically as:
sinh(x) / cosh(x).

x

to_byte (color component)

Converts a floating point pixel value to an 8-bit value that represents that number in sRGB space.

color_component

to_rec709 (color component)

Converts a floating point pixel value to an 8-bit value that represents that brightness in the rec709 standard when that standard is mapped to the 0-255 range.

color_component

to_sRGB (color component)

Converts a floating point pixel value to an 8-bit value that represents that number in sRGB space.

color_component

true ()

Always Returns 1.

none

trunc (x)

Round x to the nearest integer not larger in absolute value.

x

turbulence (x, y, z, octaves, lacunarity, gain)

This is the same as fBm() except the absolute value of the noise() function is used.

x, y, z, octaves, lacunarity, gain

x ()

Return the current frame number.

none

y (frame)

Evaluates the y value for an animation at the given frame.

optional: frame, defaults to current frame

none

# Example Nuke Scripts

Note:  Loading example scripts only works if you launched the help from Nuke and have set documentation source to local in the Behaviors > Documentation tab of the Preferences.