Mathematical Shader Processes

From C4 Engine Wiki
Jump to navigation Jump to search

This is a list of the mathematical shader processes that are available in the Shader Editor under the Math tab.

Process

Description

Absolute Value

Inputs: Value A

Output: Value of size matching A

Calculates the absolute value of each component of the input A.

Add

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise sum of the inputs A and B.

Average

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise average of the inputs A and B.

Cosine

Inputs: Scalar A

Output: Scalar

Calculates the cosine of the input A, where the input is measured in radians.

Cross Product

Inputs: 3D vectors A and B

Output: 3D vector

Calculates the cross product of the inputs A and B.

Divide

Inputs: Value A, Scalar B

Output: Value of size matching A

Calculates the quotient of each component of the input A and the scalar input B.

Tip: If you're dividing by a constant value, then it would be more efficient to multiply by the reciprocal of the constant. For example, you should multiply by 0.5 instead of dividing by 2.0.

Dot Product 3D

Inputs: 3D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Dot Product 4D

Inputs: 4D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Exp Base 2

Inputs: Scalar A

Output: Scalar

Calculates 2 raised to the power given by the input A.

Expand

Inputs: Value A

Output: Value of size matching A

Multiplies each component of the input A by 2.0 and then subtracts 1.0.

Floor

Inputs: Value A

Output: Value of size matching A

Calculates the floor of each component of the input A. To calculate a ceiling, negate the input and output of the Floor process.

Fraction

Inputs: Value A

Output: Value of size matching A

Calculates the fraction of each component of the input A. The fraction of a number is the difference between that number and its floor.

Invert

Inputs: Value A

Output: Value of size matching A

Subtracts each component of the input A from 1.0.

Linear Interpolate

Inputs: Values A, B, and t

Output: Value of size matching largest of A, B, and t

Calculates the linear interpolation between the components of A and B using the components of the input t as the interpolation parameter.

Log Base 2

Inputs: Scalar A

Output: Scalar

Calculates the logarithm base 2 of the input A. If the input is not positive, then the result is undefined.

Magnitude 3D

Inputs: 3D vector A

Output: Scalar

Calculates the magnitude of the input A.

Maximum

Inputs: Values A and B (required), value C (optional)

Output: Value of size matching larger of A, B, and C

Calculates the componentwise maximum of the inputs A, B, and C. If input C is omitted, then the maximum of only A and B is calculated.

Minimum

Inputs: Values A and B (required), value C (optional)

Output: Value of size matching larger of A, B, and C

Calculates the componentwise minimum of the inputs A, B, and C. If input C is omitted, then the minimum of only A and B is calculated.

Multiply

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise product of the inputs A and B.

Multiply Add

Inputs: Values A, B, and C

Output: Value of size matching largest of A, B, and C

Calculates the componentwise product of the inputs A and B and then adds the components of the input C.

Normalize 3D

Inputs: 3D vector A

Output: 3D vector

Normalizes the input A. If the input is the zero vector, then the result is undefined.

Power

Inputs: Scalars A and B

Output: Scalar

Calculates the input A raised to the power of the input B. If the input A is negative, then the result is undefined. If the input A is zero and the input B is not positive, then the result is undefined.

Tip: If you're just squaring a value, then it would be more efficient to multiply the value by itself. That is, you should calculate A × A using the Multiply process instead of raising A to the power of 2.

Reciprocal

Inputs: Scalar A

Output: Scalar

Calculates the reciprocal of the input A. If the input is zero, then the result is undefined.

Reciprocal Square Root

Inputs: Scalar A

Output: Scalar

Calculates the reciprocal square root of the input A. If the input is not positive, then the result is undefined.

Round

Inputs: Value A

Output: Value of size matching A

Rounds each component of the input A to the nearest integer.

Saturate

Inputs: Value A

Output: Value of size matching A

Clamps each component of the input A to the range [0,1].

Set if Equal

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is equal to the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Set if Greater Equal

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is greater than or equal to the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Set if Greater Than

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is greater than the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Set if Less Equal

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is less than or equal to the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Set of Less Than

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is less than the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Set if Not Equal

Inputs: Value A (required), Value B (optional)

Output: Value of size matching larger of A and B

For each component of the inputs A and B, the corresponding component of the output is set to 1.0 if the component of A is not equal to the same component of B, and 0.0 otherwise. If input B is omitted, then it is assumed to be a vector of zeros.

Sine

Inputs: Scalar A

Output: Scalar

Calculates the sine of the input A, where the input is measured in radians.

Square Root

Inputs: Scalar A

Output: Scalar

Calculates the square root of the input A. If the input is negative, then the result is undefined.

Subtract

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise difference of the inputs A and B.

See Also