3 ms·
> GLSL supports the ternary ?: operator. WGSL does not support this, but provides the built-in function select(falseValue, trueValue, condition) which does much
by skinner_ 5y ago
> GLSL supports the ternary ?: operator. WGSL does not support this, but provides the built-in function select(falseValue, trueValue, condition) which does much the same thing (although mind that parameter order!).
I'd really like to hear a justification for that parameter order. To me it seems like the 4th best option out of 6.
- jamienicol 5y agoIt could be because it matches the order of glsl's `mix()`. Not sure why glsl chose that order, though perhaps you might find it less unintuitive for an interpolation than a select. (Mix acts as a select rather than interpolation when the third argument is a boolean)
- skinner_ 5y agoThat makes much sense, thanks! But then why didn't they call it mix() or lerp() or interpolate()? I would have immediately spotted the logic behind it. EDIT: I think I get it, there also a mix() with a different type signature but same parameter order.
- kevingadd 5y agolerp(zero, one, t) -> select(falseValue, trueValue, condition ? 1.0 : 0.0)