Game Development Reference
In-Depth Information
Zero-based:
M._m00 = M._m01 = M._m02 = M._m03 = 0.0f;
M._m10 = M._m11 = M._m12 = M._m13 = 0.0f;
M._m20 = M._m21 = M._m22 = M._m23 = 0.0f;
M._m30 = M._m31 = M._m32 = M._m33 = 0.0f;
Sometimes we want to refer to a particular row vector in a matrix. We
can do so using a single array subscript syntax. For example, to refer to
the i th row vector in a matrix M , we would write:
vector ithRow = M[i]; // get the ith row vector in M
Note: We can initialize variables in HLSL using the following two
types of syntax:
vector u = {0.6f, 0.3f, 1.0f, 1.0f};
vector v = {1.0f, 5.0f, 0.2f, 1.0f};
Or, equivalently, using a constructor style syntax:
vector u = vector(0.6f, 0.3f, 1.0f, 1.0f);
vector v = vector(1.0f, 5.0f, 0.2f, 1.0f);
Some other examples:
float2x2 f2x2 = float2x2(1.0f, 2.0f, 3.0f, 4.0f);
int2x2 m = {1, 2, 3, 4};
int n = int(5);
int a = {5};
float3 x = float3(0, 0, 0);
16.3.4 Arrays
We can declare an array of a particular type using familiar C++ syntax.
For example:
float M[4][4];
half p[4];
vector v[12];
16.3.5 Structures
Structures are defined exactly as they are in C++. However, struc-
tures in HLSL cannot have member functions. Here is an example of a
structure in HLSL:
struct MyStruct
{
matrix T;
vector n;
float f;
int
x;
bool
b;
};
Search WWH ::




Custom Search