As a note, gpus are not that good when it comes to integer math, they are highly specialized for floats…
At least on the not modern gpus this was an issue
I also noticed that modern GPUs handles branching very well. I tested two versions of my shader, one full of if(), the other one with almost all of them replaced by ‘math’ ( Avoiding Shader Conditionals ). On two test scenes (~180fps and ~120fps) I did not noticed any significant difference, all of them was within an error, because it was an 2-3 fps difference for 180fps.
Graphics card I used: GTX 750 Ti
I think this is true only for very modern GPUs, when they do nice optimizations, such removing some simple branchings… To mobile devices, we still need avoid branching.
There’s nothing wrong with using conditionals per-se… But specifically using them to avoid doing expensive calculations doesn’t work, e.g.:
if (needToDoIt) {
doSomethingReallyComplicated();
}
This doesn’t actually save you from doing the complicated computation, just makes the side effects from it not visible. So in most cases you won’t see any performance difference with or without the if statement because the computation has to be done in either case.