Skip to content

Instantly share code, notes, and snippets.

@marklundin
Created October 7, 2016 13:20
Show Gist options
  • Save marklundin/4f3374383adf071f8bdb1206dba79eff to your computer and use it in GitHub Desktop.
Save marklundin/4f3374383adf071f8bdb1206dba79eff to your computer and use it in GitHub Desktop.
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