CG中的类型
2024-08-25 22:16:45
【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, , > 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 = ;
float3 fVector = { 0.2f, 0.3f, 0.4f };
也可像下面这样定义:
vector <Type, Number> VariableName vector <int, > iVector = ;
vector <double, > 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(,,,);
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[] // read the first row
参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx
最新文章
- c语言的简易日历
- 不能用100%ie6不兼容
- Python多线程学习笔记
- Retrofit2.0+OkHttp打印Request URL(请求地址参数)
- 【Sort】多种排序
- Java对数函数及Java对数运算
- python的 a,b=b,a+b 和 a=b b=a+b 的区别(经典)
- python的单、双、多分支流程控制
- PHP获取新插入的主键id
- A1制作文件夹目录
- 洛谷P3620 数据备份
- hbase大规模数据写入的优化历程 ,ZZ
- JDK 升级问题小结
- 牛客OI周赛7-提高组
- 9、SQL逻辑查询语句执行顺序
- Python中的对象行为与特殊方法(二)类型检查与抽象基类
- Python基础4--一看就会的选择与循环
- flask session,蓝图,装饰器,路由和对象配置
- vue注册全局属性
- Spring Boot中使用JavaMailSender发送邮件