Skip to content

Instantly share code, notes, and snippets.

@galek
Created May 30, 2016 00:58
Show Gist options
  • Save galek/7bac754ccf2ce3a2b595b18be6e30937 to your computer and use it in GitHub Desktop.
Save galek/7bac754ccf2ce3a2b595b18be6e30937 to your computer and use it in GitHub Desktop.
Compute frag pos in view space
// Compute frag pos in view space
vec3 fragPos;
{
float depth = gl_FragCoord.z;
fragPos.z = u_lightingUniforms.projectionParams.z
/ (u_lightingUniforms.projectionParams.w + depth);
vec2 screenSize = 1.0 / RENDERER_SIZE;
vec2 ndc = gl_FragCoord.xy * screenSize * 2.0 - 1.0;
fragPos.xy = ndc * u_lightingUniforms.projectionParams.xy * fragPos.z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment