Skip to content

Instantly share code, notes, and snippets.

@mattorb
Created February 5, 2013 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattorb/4718078 to your computer and use it in GitHub Desktop.
Save mattorb/4718078 to your computer and use it in GitHub Desktop.
Eliminate dynamic branching in glsl - OpenGL ES 2.0
// Original w/branching
float result;
if(varA < varB)
{
result=100.0;
}
else
{
result=32.0;
}
// Removed dynamic branching
float aLessThanBThen0Else1 = clamp(sign(varA-varB), 0.0, 1.0);
float result = mix(100.0, 32.0, aLessThanBThen0Else1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment