Mathematical Shader Processes

From C4 Engine Wiki

Jump to: navigation, search
Absolute Value

Image:sh_abs.gif

Inputs: Value A

Output: Value of size matching A

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

Add

Image:sh_add.gif

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

Image:sh_avg.gif

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

Image:sh_cos.gif

Inputs: Scalar A

Output: Scalar

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

Cross Product

Image:sh_xpd.gif

Inputs: 3D vectors A and B

Output: 3D vector

Calculates the cross product of the inputs A and B.

Divide

Image:sh_div.gif

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

Image:sh_dp3.gif

Inputs: 3D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Dot Product 4D

Image:sh_dp4.gif

Inputs: 4D vectors A and B

Output: Scalar

Calculates the dot product of the inputs A and B.

Exp Base 2

Image:sh_ex2.gif

Inputs: Scalar A

Output: Scalar

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

Expand

Image:sh_vex.gif

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

Image:sh_flr.gif

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

Image:sh_frc.gif

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

Image:sh_inv.gif

Inputs: Value A

Output: Value of size matching A

Subtracts each component of the input A from 1.0.

Linear Interpolate

Image:sh_lrp.gif

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

Image:sh_lg2.gif

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.

Maximum

Image:sh_max.gif

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

Image:sh_min.gif

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

Image:sh_mul.gif

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

Image:sh_mad.gif

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

Image:sh_nrm.gif

Inputs: 3D vector A

Output: 3D vector

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

Power

Image:sh_pow.gif

Inputs: Scalars A and B

Output: Scalar

Calculates the input A raised to the power of the input B.

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

Image:sh_rcp.gif

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

Image:sh_rsq.gif

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

Image:sh_rnd.gif

Inputs: Value A

Output: Value of size matching A

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

Saturate

Image:sh_sat.gif

Inputs: Value A

Output: Value of size matching A

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

Set if Greater Equal

Image:sh_sge.gif

Inputs: Values A and B

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.

Set of Less Than

Image:sh_slt.gif

Inputs: Values A and B

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.

Sine

Image:sh_sin.gif

Inputs: Scalar A

Output: Scalar

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

Square Root

Image:sh_sqr.gif

Inputs: Scalar A

Output: Scalar

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

Subtract

Image:sh_sub.gif

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

Personal tools