Mathematical Shader Processes

From Tombstone Engine Wiki
Jump to: navigation, 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

Shader abs.png

Inputs: Value A

Output: Value of size matching A

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

Add

Shader add.png

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.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

Average

Shader avg.png

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.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

Cosine

Shader cos.png

Inputs: Scalar A

Output: Scalar

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

Cross Product

Shader xpd.png

Inputs: 3D vectors A and B

Output: 3D vector

Calculates the cross product of the inputs A and B.

Divide

Shader div.png

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

Shader dp3.png

Inputs: 3D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Dot Product 4D

Shader dp4.png

Inputs: 4D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Exp Base 2

Shader ex2.png

Inputs: Scalar A

Output: Scalar

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

Expand

Shader expand.png

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

Shader flr.png

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

Shader frc.png

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

Shader invert.png

Inputs: Value A

Output: Value of size matching A

Subtracts each component of the input A from 1.0.

Linear Interpolate

Shader lrp.png

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.

LOD: If either input A or B is high-detail only, then the other input in that pair is passed through unchanged in the low-detail shader, and the input t is ignored.

Log Base 2

Shader lg2.png

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

Shader magnitude3d.png

Inputs: 3D vector A

Output: Scalar

Calculates the magnitude of the input A.

Maximum

Shader max.png

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise maximum of the inputs A and B.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

Minimum

Shader min.png

Inputs: Values A and B

Output: Value of size matching larger of A and B

Calculates the componentwise minimum of the inputs A and B.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

Multiply

Shader mul.png

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.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

Multiply Add

Shader mad.png

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.

LOD: If any two inputs are high-detail only, then the third input is passed through unchanged in the low-detail shader. If only the input C is high-detail only, then the product of the inputs A and B is calculated. If only the input A or only the input B is high-detail only, then the sum of the other input in that pair and the input C is calculated.

Normalize 3D

Shader normalize3d.png

Inputs: 3D vector A

Output: 3D vector

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

Power

Shader pow.png

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

Shader rcp.png

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

Shader rsq.png

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

Shader round.png

Inputs: Value A

Output: Value of size matching A

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

Saturate

Shader sat.png

Inputs: Value A

Output: Value of size matching A

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

Set if Equal

Shader seq.png

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

Shader sge.png

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

Shader sgt.png

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

Shader sle.png

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

Shader slt.png

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

Shader sne.png

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

Shader sin.png

Inputs: Scalar A

Output: Scalar

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

Square Root

Shader sqrt.png

Inputs: Scalar A

Output: Scalar

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

Subtract

Shader sub.png

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.

LOD: If either input is high-detail only, then the other input is passed through unchanged in the low-detail shader.

See Also