如果一个向量等于另一个向量,并且向量不相等,我想设置一个float值1.00.0
if( v1 == v2 ) floatVal = 1.0 ;
else floatVal = 0.0 ;
Run Code Online (Sandbox Code Playgroud)
但它不是"更快"或只是设置优化
floatVal = (v1 == v2) ;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.你不能隐式(或明确地)将float转换为bool?有没有办法做到这一点,还是我必须使用if语句分支?
小智 11
你没试过"浮动(bool)"功能吗?
GLSLangSpec.Full.1.20.8.pdf第5.4.1节说你可以完成所有这些转换.
谢谢.
小智 5
CuriousChettai是对的.写吧:
floatVal = float(v1 == v2);
Run Code Online (Sandbox Code Playgroud)
如果您指定的值可能会导致精度损失,则GLSL会给出编译错误.所以你可以这样做:
float f = 3; // works
int i = 3.0; // compiler-error
int j = int(3.0); // works
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8265 次 |
| 最近记录: |