A struct is a user-customizable data type that contains any number of components. Each component of a struct must be one of the basic data types.
struct { Type[RxC] VariableName; ... }
where:
Type[RxC] | A structure member that contains at least one element, but may optionally contain R rows by C columns of elements. Every element must be of the same type (see basic types ). The number of rows and columns is a positive integer between 1 and 4. |
VariableName | An ASCII string that uniquely identifies the variable name. |
... | Any number of additional members. |
Here are some examples:
struct struct1 { int a; // single integer } struct struct2 { int a; // single integer float b; // single float int4x1 iMatrix; // integer matrix with 4 rows, 1 column }
When compiled into shader code using the Shader Compilers, each structure member is assigned to a separate shader register, which is consistent with how variables are packed by a language compiler.
struct L { float4 pos; float3 diff; float att; };
Even though the second and third members could theoretically be packed into a single, four-component register, the compiler will assign pos to the first available register, diff to the second available register, and att to the third available register.