Created
February 5, 2013 21:50
-
-
Save mattorb/4718078 to your computer and use it in GitHub Desktop.
Eliminate dynamic branching in glsl - OpenGL ES 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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