The true and False keywords provided in HLSL are the same as C + +.
Int:32 bit signed integer half:16 bit floating point number float:32 bit floating point number double:64 bit floating point number
FLOAT2 float3 float4 are 2D 3D 4D vectors respectively.
Composite components: (the copy operation below) does not necessarily copy each component, it can copy only the x, Y components.
Float4 u = {1.0f2.0f3.0f4.0f= {0.0f0.0f 5.0f 6.0f// v = {4.0f, 2.0f, 2.0f, 1.0f}
Matrix Type:
FLOATMXN MATMXN;
such as: float3x4:3x4 matrix, each element is a float type. You can also create other types of matrices, such as int2x2, half3x3, and bool4x4.
In addition to using FLOAT4 and float4x4, vectors and matrices can be used when representing a 4D vector and matrix:
We can use the double subscript array syntax to access the matrix elements, or access the elements in the matrix as you would access the struct members. The element names can be represented in the following two ways:
Numbering starting from 1:
M._11 = M._12 = m._13 = M._14 = 0.0f;
m._21 = m._22 = m._23 = m._24 = 0.0f;
Numbering starting from 0:
m._m00 = M._M01 = m._m02 = M._m03 = 0.0f;
M._M10 = M._M11 = M._m12 = M._m13 = 0.0f;
Sometimes it is necessary to refer to a line vector in the matrix, which we can do by single subscript array syntax:
FLOAT3 ithrow = M[i]; Get the ith row vector in M
Structs are defined in exactly the same way as C + +, except that structs in HLSL cannot contain member functions. HLSL provides a very flexible type-conversion mechanism. The type conversion syntax in HLSL is the same as the C language.
Keywords in HLSL:
ASM BOOL compile const decl dodouble else extern false float forhalf if in inline inout Intmatrix out pass pixelshader return samplershared static string struct technique texturetrue typedef Uniform vector vertexshader voidvolatile while
Variable elevation for binocular operations:
For binocular operations, when the dimensions of the left and right operands are not the same, the operand with the smaller dimension will be promoted (converted) to the same dimension as the operand with the larger dimension.
For binocular operations, when the left and right operands are not of the same type, the lower-precision operand increases (translates) to the same type as the operand with the higher precision.
Functions in HLSL have the following characteristics:
1. The function uses a syntax similar to C + +.
2. The parameters are passed by value.
3. Recursion is not supported.
4. All functions are inline functions.
HLSL provides a large number of functions for 3D drawings, and some of them are listed below: (many functions provide the appropriate overloaded version for the "All" built-in types that make the function meaningful.) )
1.abs (x)-the absolute value returned.
2.ceil (x)-Returns the smallest integer greater than or equal to X.
3.clamp (x, A, b)-intercepts x into the [a, b] interval and returns the truncated value. (That is, when x< a, returns a; when x> B returns B; When x∈[A, b] returns x. )
4.clip (x)-the function can only be called in the pixel shader, and when x< 0 o'clock, the current pixel is discarded and no subsequent processing is done.
5.cos (x)-the cosine value returned, where x is in radians.
6.cross (U, v)-Returns the cross product of U and v.
7.degrees (x)-converts x from radians to angles.
8.determinant (m)-Returns the determinant of the Matrix M.
9.distance (U, v)-returns the distance between the point U and v.
10.dot (U, v)-Returns the dot product of U and v.
11.floor (x)-Returns the largest integer less than or equal to X.
12.frac (x)-Returns the decimal part of the floating-point number (that is, the mantissa). For example, when x= (235.52, 696.32), frac (x) = (0.52, 0.32).
13.length (v)-Returns the length of the vector v.
14.lerp (U, V, t)-Calculates linear interpolation between U and V based on the parameter T, where t∈[0, 1].
15.log (x)-Returns ln (x).
16.LOG10 (x)-Returns log (x).
17.LOG2 (x)-Returns log (x).
18.max (x, y)-returns X when X≥y, or vice versa, returns Y.
19.min (x, y)-returns X when X≤y, or vice versa, returns Y.
20.mul (M, N)-Returns the matrix product MN. Note that the matrix product MN must satisfy the definition of matrix multiplication. If M is a vector, M will be treated as a line vector to satisfy the vector-matrix multiplication definition. If n is a vector, then n is treated as a column vector to satisfy the matrix-vector multiplication definition.
21.normalize (v)-Returns the normalized v-vector, or V/‖v‖.
22.pow (b, N)-returns B^N.
23.radians (x)-converts x from angle to radians.
24.saturate (x)-Returns clamp (x, 0.0, 1.0).
25.sin (x)-Returns the sine of x, where the units of x are in radians.
26.sincos (in ×, out S, out c)-Returns the sine and cosine values of x, where x is in radians.
27.SQRT (x)-returns √X.
28.reflect (V, N)-calculates the reflection vector based on the in-shot amount V and the surface normal N.
29.refract (V, N, ETA)-calculates the reflection vector based on the refractive index of the incoming shot V, the surface normal n, and the two materials compared to the ETA. Readers can find information about Snell refraction laws on the Internet or in physics books.
30.RSQRT (x)-returns 1/√X.
31.tan (x)-Returns the tangent of x, where the units of x are in radians.
32.transpose (m)-Returns the transpose matrix of M.
33.texture2d::sample (S, texc)-samples a 2D texture map based on Samplerstate object s and 2D texture coordinates texc. (The Samplerstate object specifies texture filtering and texture addressing modes.) )
34.texture2d::samplelevel (S, Texc, LOD)-samples a 2D texture map based on Samplerstate object s and 2D texture coordinates texc. (The Samplerstate object specifies texture filtering and texture addressing modes.) The difference between this function and Texture2d::sample is the 3rd parameter, which specifies the multilevel asymptotic texture layer to be sampled. For example, when LOD is specified as 0 o'clock, the function samples the topmost multilevel asymptotic texture layer. Use this function to manually specify the multilevel asymptotic texture layer to be sampled.
35.texturecube::sample (S, v)-samples a cube map based on the Samplerstate object S and 3D find vector v. (The Samplerstate object specifies texture filtering and texture addressing modes.) )
Introduction to Advanced coloring languages