Language:
Page Info
Tags:
Engine Version:

# 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.

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.

## 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.0) is (0.2,0.4,1.0).

## ArcSine

Click for full image.

The Arcsine expression outputs the inverse sine function. This is an expensive operation that is not reflected by the instruction count.

## ArcSineFast

Click for full image.

The ArcsineFast expression outputs the approximate inverse sine function. Input must be between -1 and 1.

## ArcCosine

Click for full image.

The Arccosine expression outputs the inverse cosine function. This is an expensive operation that is not reflected by the instruction count.

## ArcCosineFast

Click for full image.

The ArccosineFast expression outputs the approximate inverse cosine function. Input must be between -1 and 1.

## ArcTangent

Click for full image.

The Arctangent expression outputs the inverse tangent function. This is an expensive operation that is not reflected by the instruction count.

## ArcTragnetFast

Click for full image.

The ArctangentFast expression outputs the approximate inverse tangent function.

## ArcTangent2

Click for full image.

The Arctangent2 expression uses inverse tangent of x / y where input signs are used to determine quadrant. This is an expensive operation that is not reflected by the instruction count.

## ArcrTangent2Fast

Click for full image.

The Arctangent2Fast expression is an approximate inverse tangent of X / Y where input signs are used to determine quadrant.

## 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).

## 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 an input range of (0.0) to (1.0) 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.

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.4,1.0) and the G channel will produce an output of (0.4), which appears as a 40% bright grayscale value when used as a color vector.

## Cosine

The Cosine expression outputs the value of a cosine wave over the input range of [0, 1] and the output range of [-1, 1], both repeating. Most commonly, this is used to output a continuous oscillating waveform by connecting a Time expression to its input, but it can also be used to create ripples in worldspace or screenspace, or any other application where a continuous, smooth cycle is needed. A visual representation of the wave is shown below, scaled to the [0, 1] output range:

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).

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.

## 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. Division by zero in any channel will result in that channel containing the local hardware's "infinity" implementation, which is usually a very large, positive value.

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: Using Divide with A=(1.0) and B=(5.0) outputs (0.2), which appears as a dark gray.

## DotProduct

The DotProduct expression computes the dot product, which can be described as the length of one vector projected onto the other, or as the cosine between the two vectors multiplied by their magnitudes. 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 the same length as A.

## 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).

## FMod

The FMod expression returns the floating-point remainder of the division operation of the two inputs. The Dividend (input "A") can be any value, but negative Dividends will result in negative results. The Divisor (second input) should not be zero as this implies a division by zero, but whether the Divisor is negative or positive will not affect the result. A common use case is to make a material that brightens up to a maximum value, then immediately drops back to the minimum value on the next frame, only to begin climbing toward the maximum again.

In this example, FMod takes a zero-to-one UV progression and converts it into a repeating cycle every 0.2 UV units on the X axis in the green channel.

## Frac

The Frac expression takes in values and outputs the fractional portion of those values. In other words, for an input value "X", the result is "X minus Floor of X". The output value will range from zero to one, inclusive on the low end, but not the high end. See also Ceil and Floor .

Examples: Frac of (0.2) is (0.2). Frac of (-0.2) is (0.8). Frac of (0.0,1.6,1.0) is (0.0,0.6,0.0).

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.

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.

## Max

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

This node is similar to Photoshop's Lighten.

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 and outputs the lower of the two.

This node is similar to Photoshop's Darken.

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 R channel of the second; the G chanWnel of the first is multiplied by the G channel of 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.

## Normalize

The Normalize expression calculates and outputs the normalized value of its input. Normalized vectors (also called "unit vectors") have an overall length of 1.0. This means each component of the input is divided by the total magnitude (length) of the vector.

Examples: Passing either (0,2,0) or (0,0.2,0) through Normalize will output (0,1,0). Passing (0,1,-1) through Normalize will output (0, 0.707, -0.707). The only special case is an all-zero vector, which will be unchanged.

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

## OneMinus

The OneMinus expression takes an input value "X" and outputs "One Minus X". 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.

## 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 sort of contrast adjustment, where very bright values are dimmed slightly, but darker values are decreased drastically.

## Round

The Round expression rounds the value up to the next whole number if the fractional part is greater than or equal to half, else rounds down.

Examples:

• A value of 1.1 will be Round down to a value of 1.

• A value of 1.4 will be Round down to a value of 1.

• A value of 1.5 will be Round up to a value of 2.

• A value of 1.85 will be Round up to a value of 2.

## Saturate

The Saturate node clamps the value between 0 and 1. The instruction cost of Saturate is almost free on most modern graphics hardware.

Example Usage: This node should be used whenever you need to clamp an output or input value between 0 and 1.

## Sine

The Sine expression outputs the value of a Sine wave over the input range of [0, 1] and the output range of [-1, 1], both repeating. The difference between this and the output of the Cosine expression is the output waveform is offset by one-quarter of the period, meaning that `Cos(X)` is equal to `Sin(X + 0.25)`. Most commonly, this is used to output a continuous oscillating waveform by connecting a Time expression to its input, but it can also be used to create ripples in worldspace or screenspace, or any other application where a continuous, smooth cycle is needed. A visual representation of the wave is shown below, scaled to the [0, 1] output range:

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).

## SquareRoot

The SquareRoot expression outputs the square root of the input value. If applied to a vector, each component will be handled individually.

## 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.

## Tangent

Click for full image.

The Tangent node outputs the tangent of the specified value.

## Truncate

The Truncate node truncates a value by discarding the fractional part while leaving the whole number untouched.

Examples:

• A value of 1.1 will be Truncated to a value of 1.

• A value of 1.4 will be Truncated to a value of 1.

• A value of 2.5 will be Truncated to a value of 2.

• A value of 3.1 will be Truncated to a value of 3.

Tags