Mathematical Shader Processes

From C4 Engine Wiki
Jump to: navigation, search

Process

Description

Absolute Value

Sh abs.png

Inputs: Value A

Output: Value of size matching A

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

Add

Sh 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

Sh 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

Sh cos.png

Inputs: Scalar A

Output: Scalar

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

Cross Product

Sh xpd.png

Inputs: 3D vectors A and B

Output: 3D vector

Calculates the cross product of the inputs A and B.

Divide

Sh 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

Sh dp3.png

Inputs: 3D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Dot Product 4D

Sh dp4.png

Inputs: 4D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Exp Base 2

Sh ex2.png

Inputs: Scalar A

Output: Scalar

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

Expand

Sh 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

Sh 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

Sh 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

Sh invert.png

Inputs: Value A

Output: Value of size matching A

Subtracts each component of the input A from 1.0.

Linear Interpolate

Sh 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

Sh 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

Sh magnitude3d.png

Inputs: 3D vector A

Output: Scalar

Calculates the magnitude of the input A.

Maximum

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh round.png

Inputs: Value A

Output: Value of size matching A

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

Saturate

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh 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

Sh sin.png

Inputs: Scalar A

Output: Scalar

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

Square Root

Sh 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

Sh 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