GLSL函数step
返回一个浮点数(0.0f
或1.0f
)或浮点数向量。有没有办法让它返回一个整数?我试图用它来抵消索引(不引入if
语句):
const int[8] constIndicies = int[](
0,1,2,3,
1,3,0,2);
...
float ratioEdge = 17.0f;
float myFloatValue = 9.0f;
... constIndicies[4*step(ratioEdge, myFloat)] ...
但随着它返回浮动,这是行不通的。并将其转换为int似乎是错误的。
答案 0 :(得分:0)
唯一的方法是将step(ratioEdge, myFloat)
转换为int。
constIndicies[4*int(step(ratioEdge, myFloat))]
编辑: 为了回应Rabbid76,我删除了圆形建议。
答案 1 :(得分:0)
在挖掘之后,它似乎是step
函数的最接近的等价物,它返回int
在标量的构造函数中。
int myStepInt = int(myFloat > ratioEdge); // returns integer 1 or 0.
以上是
的替代方案int myStepInt = myFloat > ratioEdge ? 1 : 0;
上述任何一个是否比内置step
函数更多/更少无分支仍然是我的一个谜。