3 ms·
Code that uses min, max, clip, clamp, saturate, etc. when that is straightforwardly what operation is needed is clearer, more explicit, more concise and potenti
by mattnewport 3y ago
Code that uses min, max, clip, clamp, saturate, etc. when that is straightforwardly what operation is needed is clearer, more explicit, more concise and potentially faster. When used this way they are just straightforwardly better than equivalent if then statements.
Occasionally you see code that uses combinations of these in less obvious ways to do some more complex operation and I can see how one could argue that in rare cases that ends up less clear than if then statements but I've never really encountered that in many years of reading shader code.
There are other reasons to prefer functions over if then in shader code not discussed here as well, like replacing step with smoothstep for antialiasing.
- gumby 3y agoIts a shame that few modern languages make using clamp, saturate etc as simple as “normal” arithmetic.