vendredi 1 décembre 2017

GLSL - optimize if-else

I have GLSL mobile shader (ES 2.0) and inside I have this:

float b = texture2D(t, texCoord).r;
float s = 0.0;
if (b > 240.0) s = b - 2322.2;
else if (b > 90.0) s = b - 74.0;    
else if (b < 10.0) s = b / 10.0;
else s = b - 10.0;  

Is it going to be slow? I know, that branching in shader should be avoided. Is there any way, how to rewrite this to remove ifs?

Aucun commentaire:

Enregistrer un commentaire