Shadder and Effect - 1.7 Built-in function

zhaozj2021-02-16  49

1.7 built-in function

Read this article shows that you have agreed to the statement

HLSL has a collection of built-in functions that are very useful for 3D graphics. The following table is a list of deleted. In the next chapter, we will use some of these functions to practice. And now, familiar with them is enough.

Note: To get more reference, you can see the full list of built-in HLSL functions in the DirectX document, under the Content page, then go to DirectX Graphics / Reference / Shader Reference / High Level Shader Language / Intrinsic Functions.

Translator Note: In the following table, // // represents the modulus Variable model (for example, the absolute value of the vector).

function

description

ABS (x)

Return | X |.

CEIL (x)

Returns the minimum integer of ≥ x.

CLAMP (X, A, B)

Intercept the results within the range of X to [A, B] and returns the result.

COS (x)

Returns the cosine of x, where the X unit is an arc.

Cross (U, V)

Return U × V (fork).

Degrees (x)

Convert X from the arc to the angle.

DETERMINANT (M)

Returns the row of matrix M.

Distance (U, V)

Returns the distance between u points and V points || V - u ||.

DOT (U, V)

Returns U · V (dot).

Floor (x)

Returns the maximum integer of ≤ X.

Length (v)

Return || V ||.

LERP (U, V, T)

Linear interpolation between U and V, according to parameter T ε [0, 1].

Log (x)

Returns Ln (X).

Log10 (x)

Returns log10 (x).

Log2 (x)

Returns log2 (x).

Max (x, y)

If x ≥ y, returns x; otherwise returns y.

MIN (X, Y)

If x ≤ y, return x; otherwise returns y.

MUL (M, N)

Returns the matrix product MN. Note: The matrix product must be defined. If M is a vector, it is used as a row vector, the vector-matrix multiplication is defined. Similarly, if n is a vector, he is used as a column vector, the matrix-vector multiplication is defined.

Normalize (V)

Returns v / ∥V∥.

Pow (b, n)

Returns BN.

Radians (x)

Convert X from the angle to the radians.

Reflect (v, n)

The given vector V and the surface normal N, calculate its reflection vector.

Refract (V, N, ETA)

The ratio ETA of two indexes of two indexes for the surface normal N and two materials are calculated. Turn off the rules in the physical book or search for information about refraction (reflection) on the Internet.

RSQRT (x)

Returns the countdown of the square root of x.

Saturate (x)

Returns CLAMP (X, 0.0, 1.0).

sin (x)

Returns the sinusoid of x, where the X unit is an arc.

Sincos (In x, Out S, OUT C)

Returns the sinusoidal and cosine of X, where the X unit is an arc.

SQRT (x)

Returns the square root of x.

Tan (x)

Returns the orthosis of x, where the X unit is an arc.

Transpose (M)

Returns the transposition of the MT.

Most functions have been overloaded to make it meaningful for all built-in types. For example, ABS is meaningful for all numeric types, so it is overloaded for all of these numerical types. For example, the fork of the fork is only meaningful to 3D vectors, so it overloads all types of 3D vectors (such as int, float, double 3D vectors). On the other hand, linear interpolation -lerp, which is meaningful for numerical, 2D, 3D, and 4D vectors, so these types are overloaded. Note: If you pass a function of a non-numeric type to a (requirement) value type, it is a function that can only operate the numeric type (such as: cos (x)), then this function will pass every Identity operation. For example, you write:

Floats v = float3 (0.0F, 0.0F, 0.0F);

v = cos (v);

The function will operate for each component: v = (COS (X), COS (Y), COS (Z)).

The following example shows how these inherent functions may be called:

Float x = sin (1.0f); // sine of 1.0f radian.

FLOAT Y = SQRT (4.0f); // Square root of 4.

Vector u = {1.0F, 2.0F, -3.0F, 0.0F};

Vector v = {3.0F, -1.0F, 0.0F, 2.0F};

FLOAT S = DOT (U, V); // Compute Dot Product of U and V.

Float3 I = {1.0F, 0.0F, 0.0F};

FLOAT3 J = {0.0F, 1.0F, 0.0F};

FLOAT3 K = Cross (I, J); // Compute Cross Product of i and j.

Matrix m = {1.0F, 2.0F, 3.0F, 4.0F};

Matrix t = transpose (m); // compute transport

[Declaration]: Introduction to 3D Game Programming With DirectX 9.0 "in this article, it is limited to the translator level, and it is inevitable that there is a mistake in the text. Welcome all netizen criticism; this article is only used for learning exchange and reference usage, not to use In any form of commercial use; if you need to reprint the author's own and translator's consent, maintain the integrity of the article, indicate the author, translator and source, for the consequences of violating the above terms, the translator Do not bear any responsibility. My email address is raymond_king123@hotmade.com, welcome 3D graphics and games, and friends with a certain graphical programming experience to communicate.

转载请注明原文地址:https://www.9cbs.com/read-23179.html

New Post(0)