I have this GLSL function that I am trying to optimize because it is going to be ran on many pixels of an older devices GPU. There is no room for branching inefficiency. Essentially this function returns a 0 or a 1 based on the variables actualY
shouldY
and state
float val = 0.0;
if (actualY < shouldY) {
val = 1.0;
}
if (state >= 20.0 && state < 40.0) { //The equal/not equals is VERY important
return 1.0 - val;
}
return val;
Usually I am fairly good at removing branching from GLSL code but I really don't know what to do with the range check for the state variable.
if
statements are compiled to parallel evaluation with a multiply-add to select the desired output. You should check with the profiling tool that goes with your target GPU. $\endgroup$