Math Expressions

Abs

Abs is an abbreviation for the mathematical term "absolute value". The Abs expression outputs the absolute, or unsigned, value of the input it receives. Essentially, this means it turns negative numbers into positive numbers by dropping the minus sign, while positive numbers and zero remain unchanged.

Examples: Abs of -0.7 is 0.7; Abs of -1.0 is 1.0; Abs of 1.0 is also 1.0

Example Usage: Abs is commonly used with DotProduct . DotProduct goes from -1..0..1, while taking the Abs of DotProduct will go from 1..0..1.

AbsExample.png

Add

The Add expression takes two inputs, adds them together and outputs the result. This addition operation is performed on a per channel basis, meaning that the inputs' R channels get added, G channels get added, B channels get added, etc. Both inputs must have the same number of channels unless one of them is a single Constant value. Constants can be added to a vector with any number of inputs.

Item Description

Properties

Const A Takes in the value(s) to add to. Only used if the A input is not used.
Const B Takes in the value(s) to be added. Only used if the B input is not used.

Inputs

A Takes in the value(s) to add to.
B Takes in the value(s) to be added.

Examples: Add of 0.2 and 0.4 is 0.6; Add of (0.2,-0.4,0.6) and (0.1,0.5,1.0) is (0.3,0.1,1.6); Add of (0.2,-0.4,0.6) and 1.0 is (1.2,0.6,1.6)

Example Usage: Add is often used to brighten/darken colors or to offset UV texture coordinates.

AddExample.png

AppendVector

The AppendVector expression allows you to combine channels together to create a vector with more channels than the original. For example, you can take two individual Constants values and append them to make a two-channel Constant2Vector value. This can be useful for reordering the channels within a single texture or for combining multiple grayscale textures into one RGB color texture.

Item Description

Inputs

A Takes in the value(s) to append to.
B Takes in the value(s) to be appended.

Examples: Append of 0.2 and 0.4 is (0.2,0.4); Append of (0.2,0.4) and (1.6) is (0.2,0.4,1.6).

AppendVectorExample.png

Ceil

The Ceil expression takes in value(s), rounds them up to the next integer, and outputs the result. See also Floor and Frac .

Examples: Ceil of 0.2 is 1.0; Ceil of (0.2,1.6) is (1.0,2.0).

CeilExample.png

Clamp

The Clamp expression takes in value(s) and constrains them to a specified range, defined by a minimum and maximum value. A minimum value of 0.0 and maximum value of 0.5 means that the resulting value(s) will never be less than 0.0 and never greater than 0.5.

Item Description

Properties

Clamp Mode Selects the type of clamp to be used. CMODE_Clamp will clamp both ends of the range. CMODE_ClampMin and CMODE_ClampMax will only clamp their respective ends of the range.
Min Default Takes in the value to use as the minimum when clamping. Only used when the Min input is unused.
Max Default Takes in the value to use as the maximum when clamping. Only used when the Max input is unused.

Inputs

Min Takes in the value to use as the minimum when clamping.
Max Takes in the value to use as the maximum when clamping.

Examples: Clamping 0.3 with Min 0.0 and Max 1.0 yields 0.3; Clamping 1.3 with Min 0.0 and Max 1.0 yields 1.0.

ClampExample.png

ComponentMask

The ComponentMask expression allows you to select a specific subset of channels (R, G, B, and/or A) from the input to pass through to the output. Attempting to pass a channel through that does not exist in the input will cause an error, unless the input is a single constant value. In that case, the single value is passed through to each channel. The current channels selected to be passed through are displayed in the title bar of the expression.

Item Description

Properties

R If checked, the red (first) channel of the input value will be passed through to the output.
G If checked, the green (second) channel of the input value will be passed through to the output.
B If checked, the blue (third) channel of the input value will be passed through to the output.
A If checked, the alpha (fourth) channel of the input value will be passed through to the output.

Examples: ComponentMask with an input of (0.2,0.8,1.4) and the R and B channels checked will output (0.2,1.4).

ComponentMaskExample.png

Cosine

The Cosine expression outputs the value of a sine wave over the range of [0, 1], repeating. Most commonly, this is used to output a continuous oscillating waveform by connecting a Time expression to its input. The output value will cycle back and forth between -1 and 1. A visual representation of the wave is shown below:

CosineWave.png

Item Description

Properties

Period Specifies the period of the resultant wave. In other words, this is how long one oscillation takes to occur.

Example Usage: This expression is useful anytime an oscillating effect is needed. The speed and amplitude of the oscillation can easily be controlled dynamically by multiplying the time input (speed) or the output (amplitude).

CosineExample.png

In the example above, the color would oscillate with co-sinusoidal frequency.

CrossProduct

The CrossProduct expression computes the cross product of two three-channel vector value inputs and outputs the resulting three-channel vector value. Given two vectors in space, the cross product is a vector that is perpendicular to both of the inputs.

Item Description

Inputs

A Takes in a three-channel vector value.
B Takes in a three-channel vector value.

Example Usage: CrossProduct is often used to compute directions which are perpendicular to two other directions.

CrossProductExample.png

Divide

The Divide expression takes two inputs and outputs the result of the first divided by the second. The division happens per channel, meaning that the R channel of the first is divided by the second, the G channel of the first is divided by the second, and so on. Both inputs must have the same number of values unless the divisor is a single float value. Never divide by zero.

Item Description

Properties

Const A Takes in the value(s) to be divided, the dividend. Only used if the A input is unused.
Const B Takes in the value(s) to divide by, the divisor. Only used if the B input is unused.

Inputs

A Takes in the value(s) to be divided, the dividend.
B Takes in the value(s) to divide by, the divisor.

Examples: The output of a Divide with A=(1.0,0.5,-0.4) and B=(2.0,2.0,4.0) is (0.5,0.25,-0.1)

DivideExample.png

DotProduct

The DotProduct expression computes the dot product, or the length of one vector projected onto the other. This calculation is used by many techniques for computing falloff. DotProduct requires both vector inputs to have the same number of channels.

Item Description

Inputs

A Takes in a value or vector of any length.
B Takes in a value or vector of any length.

DotProductExample.png

Floor

The Floor expression takes in value(s), rounds them down to the previous integer, and outputs the result. See also Ceil and Frac .

Examples: Floor of 0.2 is 0.0; Floor of (0.2,1.6) is (0.0, 1.0).

FloorExample.png

FMod

The FMod expression returns the floating-point remainder of the division operation of the two inputs.

FModExample.png

In this example, FMod is returning a repeating value that ramps up from 0 to 1 every second. Once 1 is reached, the value snaps back to 0 and repeats indefinitely.

Frac

The Frac expression takes in value(s) and outputs the decimal part of those values. See also Ceil and Floor .

Examples: Frac of 0.2 is 0.2; Frac of (0.0,1.6) is (0.0, 0.6).

FracExample.png

In this example, the Frac node is converting time into a series of repeating 0 - 1 progressions, causing the color to fade (via the Lerp) from green to red, then snap back to green, repeating indefinitely.

If

The If expression compares two inputs and then passes through one of three other input values based on the result of the comparison. Both compared inputs must be single float values.

Item Description

Inputs

A Takes in a single float value.
B Takes in a single float value.
A > B Takes in the value(s) to output if the value of A is greater than the value of B.
A = B Takes in the value(s) to output if the value of A is equal to the value of B.
A < B Takes in the value(s) to output if the value of A is less than the value of B.

IfExample.png

In this example, the If expression takes in a heightmap and outputs either red or green based on whether the height falls under or over a value of 0.2.

LinearInterpolate

The LinearInterpolate expression blends between two input value(s) based on a third input value used as a mask. This can be thought of as a mask to define transitions between two textures, like a layer mask in Photoshop. The intensity of the mask Alpha determines the ratio of color to take from the two input values. If Alpha is 0.0/black, the first input is used. If Alpha is 1.0/white, the second input is used. If Alpha is grey (somewhere between 0.0 and 1.0), the output is a blend between the two inputs. Keep in mind that the blend happens per channel. So, if Alpha is an RGB color, Alpha's red channel value defines the blend between A and B's red channels independently of Alpha's green channel, which defines the blend between A and B's green channels.

Item Description

Properties

Const A The value mapped to black (0.0). Only used if the A input is unconnected.
Const B The value mapped to white (1.0). Only used if the B input is unconnected.
Const Alpha Takes in the value to use as the mask alpha. Only used if the Alpha input is unconnected.

Inputs

A Takes in the value(s) mapped to black (0.0).
B Takes in the value(s) mapped to white (1.0).
Alpha Takes in the value to use as the mask alpha.

Programmers: LinearInterpolate does a per-channel lerp between A and B based on the parametric value Alpha.

LerpExample.png

Max

The Max expression takes in two inputs and then outputs the maximum of the two.

This node is similar to Photoshop's Lighten.

MaxExample.png

In the example above, A is "0" and B is "1"; therefore, "1" (white) is the resulting base color.

Item Description

Properties

Const A Takes in the first value(s). Used only if the A input is unused.
Const B Takes in the second value(s). Used only if the B input is unused.

Inputs

A Takes in the first value(s) to compare.
B Takes in the second value(s) to compare.

Min

The Min expression takes in two inputs then outputs the minimum of the two.

This node is similar to Photoshop's Darken.

MinExample.png

In the example above, A is "0" and B is "1"; therefore, "0" (black) is the resulting base color.

Item Description

Properties

Const A Takes in the first value(s). Used only if the A input is unused.
Const B Takes in the second value(s). Used only if the B input is unused.

Inputs

A Takes in the first value(s) to compare.
B Takes in the second value(s) to compare.

Multiply

The Multiply expression takes two inputs, multiplies them together, and outputs the result. Similar to Photoshop's multiply layer blend. Multiplication happens per channel, meaning that the R channel of the first is multiplied by the second; the G channel of the first is multiplied by the second, and so on. Both inputs must have the same number of values unless one of the values is a single float value.

Item Description

Properties

Const A Takes in the first value(s) to multiply. Used only if the A input is unused.
Const B Takes in the second value(s) to multiply. Used only if the B input is unused.

Inputs

A Takes in the first value(s) to multiply.
B Takes in the second value(s) to multiply.

Do not forget that materials in UE4 are not limited to [0,1]. If colors/values are greater than 1, Multiply will actually brighten colors.

Examples: Multiply of 0.4 and 0.5 is 0.2; Multiply of (0.2,-0.4,0.6) and (0.0,2.0,1.0) is (0.0,-0.8,0.6); Multiply of (0.2,-0.4,0.6) and 0.5 is (0.1,-0.2,0.3).

Example Usage: Multiply is often used to brighten or darken colors/textures.

MultiplyExample.png

Normalize

The Normalize expression calculates and outputs the normalized value of its input. This means each component of the input is divided by the L-2 norm (length) of the vector.

NormalizeExample.png

It is not necessary to normalize an expression that plugs into the Normal material output.

OneMinus

The OneMinus expression takes an input value and outputs 'one-minus-that-value'. This operation is performed per channel.

Examples: OneMinus of 0.4 is 0.6; OneMinus of (0.2,0.5,1.0) is (0.8,0.5,0.0); OneMinus of (0.0,-0.4,1.6) is (1.0,1.4,-0.6).

Example Usage: When the input colors are in the range [0,1], OneMinus has the same effect as what is commonly called "invert" -- that is, OneMinus returns the complementary color that when added to the input will produce white.

OneMinusExample.png

Power

The Power expression takes two inputs, raises Base to the Exp power, and outputs the result; in other words, Base multiplied by itself Exp times.

Item Description

Properties

Const Exponent Takes in the exponent value. Used only if the Exp input is unused.

Inputs

Base Takes in the base value.
Exp Takes in the exponent value.

Examples: Power of Base 0.5, Exp 2.0 is 0.25.

Example Usage: If the colors you pass to Power are in [0,1], Power can behave as a contrast adjustment, where only brighter values remain.

PowerExample.png

Sine

The Sine expression outputs the value of a sine wave over the range of [0, 1], repeating. Most commonly, this is used to output a continuous oscillating waveform by connecting a Time expression to its input. The output value will cycle back and forth between -1 and 1. The difference between this and the output of the Cosine expression is the output waveform is offset half the period. A visual representation of the wave is shown below:

SineWave.png

Item Description

Properties

Period Specifies the period of the resultant wave. In other words, this is how long one oscillation takes to occur.

Example Usage: This expression is useful anytime an oscillating effect is needed. The speed and amplitude of the oscillation can easily be controlled dynamically by multiplying the time input (speed) or the output (amplitude).

SineExample.png

SquareRoot

The SquareRoot expression outputs the square root of the input value. SquareRoot can operate only on a single float input value.

SqrtExample.png

Subtract

The Subtract node takes in two inputs, subtracts the second input from the first, and outputs the difference. Subtraction happens per channel, meaning that the R channel of the second input gets subtracted from the first; the G channel of the second input gets subtracted from the first, and so on. Both inputs must have the same number of channels unless the second input is a single Constant value. Constants can be subtracted from a vector with any number of inputs.

Item Description

Properties

Const A Takes in the value(s) of the minuend. Used only if the A input is unused.
Const B Takes in the value(s) of the subtrahend. Used only if the B input is unused.

Inputs

A Takes in the value(s) of the minuend.
B Takes in the value(s) of the subtrahend.

Examples: Subtract of 0.5 and 0.2 is 0.3; Subtract of (0.2,-0.4,0.6) and (0.1,0.1,1.0) is (0.1,-0.5,-0.4); Subtract of (0.2,0.4,1.0) and 0.2 is (0.0,0.2,0.8).

Example Usage: Subtract can be used to darken colors and offset UVs.

SubtractExample.png

Tags