【Matrix】
通常像下面这样定义Matrix:
int1x1 iMatrix; // integer matrix with 1 row, 1 column int4x1 iMatrix; // integer matrix with 4 rows, 1 column int1x4 iMatrix; // integer matrix with 1 row, 4 columns double3x3 dMatrix; // double matrix with 3 rows, 3 columns float2x2 fMatrix = { 0.0f, 0.1, // row 1 2.1f, 2.2f // row 2 };
也可以像下面这样定义Matrix:
matrix <Type, Number> VariableName matrix <float, 2, 2> fMatrix = { 0.0f, 0.1, // row 1 2.1f, 2.2f // row 2 };
Member access for matrix types
_m00, _m01,_m02, _m03
_m10, _m11,_m12, _m13
_m20, _m21,_m22, _m23
_m30, _m31,_m32, _m33
or
_11, _12,_13, _14
_21, _22,_23, _24
_31, _32,_33, _34
_41, _42,_43, _4
参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb509623(v=vs.85).aspx
【Vector】
通常像下面这样定义Vector:
bool bVector; // scalar containing 1 Boolean int1 iVector = 1; float3 fVector = { 0.2f, 0.3f, 0.4f };
也可像下面这样定义:
vector <Type, Number> VariableName vector <int, 1> iVector = 1; vector <double, 4> dVector = { 0.2, 0.3, 0.4, 0.5 };
【Scalar】
- bool - true or false.
- int - 32-bit signed integer.
- uint - 32-bit unsigned integer.
- dword - 32-bit unsigned integer.
- half - 16-bit floating point value. This data type is provided only for language compatibility. Direct3D 10 shader targets map all half data types to float data types. A half data type cannot be used on a uniform global variable (use the /Gec flag if this functionality is desired).
- float - 32-bit floating point value.
- double - 64-bit floating point value. You cannot use double precision values as inputs and outputs for a stream. To pass double precision values between shaders, declare each double as a pair of uint data types. Then, use the asdouble function to pack each double into the pair of uints and the asuint function to unpack the pair of uints back into the double.
【Per-Component Math Operations】
可以单独取出Vector中的分量进行计算:
float4 pos = float4(0,0,2,1); float2 f_2D; f_2D = pos.xy; // read two components f_2D = pos.xz; // read components in any order f_2D = pos.zx; f_2D = pos.xx; // components can be read more than once f_2D = pos.yy;
读取matrix的某一行:
float2 temp; float2x2 fMatrix; temp = fMatrix[0] // read the first row
参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx