Skip to content

Instantly share code, notes, and snippets.

@marklundin
Created October 7, 2016 13:20
Show Gist options
  • Select an option

  • Save marklundin/4f3374383adf071f8bdb1206dba79eff to your computer and use it in GitHub Desktop.

Select an option

Save marklundin/4f3374383adf071f8bdb1206dba79eff to your computer and use it in GitHub Desktop.

Revisions

  1. marklundin created this gist Oct 7, 2016.
    16 changes: 16 additions & 0 deletions parallax corrected cubemap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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;
    }