Created
October 7, 2016 13:20
-
-
Save marklundin/4f3374383adf071f8bdb1206dba79eff to your computer and use it in GitHub Desktop.
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
vec3 parallaxCorrectNormal( vec3 v, vec3 cubeSize, vec3 cubePos ) { | |
vec3 nDir = normalize(v); | |
vec3 rbmax = ( .5 * ( cubeSize - cubePos ) - pos ) / nDir; | |
vec3 rbmin = ( - .5 * ( cubeSize - cubePos ) - pos ) / nDir; | |
vec3 rbminmax; | |
rbminmax.x = ( nDir.x > 0. )?rbmax.x:rbmin.x; | |
rbminmax.y = ( nDir.y > 0. )?rbmax.y:rbmin.y; | |
rbminmax.z = ( nDir.z > 0. )?rbmax.z:rbmin.z; | |
float correction = min(min(rbminmax.x, rbminmax.y), rbminmax.z); | |
vec3 boxIntersection = pos + nDir * correction; | |
return boxIntersection - cubePos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment