Skip to content

Instantly share code, notes, and snippets.

@recp
Created January 15, 2018 14:32
Show Gist options
  • Save recp/d3121fe0629251b93e426c210ba9acbf to your computer and use it in GitHub Desktop.
Save recp/d3121fe0629251b93e426c210ba9acbf to your computer and use it in GitHub Desktop.
OpenGL
Source: https://www.opengl.org/discussion_boards/showthread.php/173019-View-Space-Light-Position-Moving
vec3 PositionFromDepth_DarkPhoton(in float depth)
{
vec2 ndc; // Reconstructed NDC-space position
vec3 eye; // Reconstructed EYE-space position
eye.z = near * far / ((depth * (far - near)) - far);
ndc.x = ((gl_FragCoord.x * widthInv) - 0.5) * 2.0;
ndc.y = ((gl_FragCoord.y * heightInv) - 0.5) * 2.0;
eye.x = ( (-ndc.x * eye.z) * (right-left)/(2*near)
- eye.z * (right+left)/(2*near) );
eye.y = ( (-ndc.y * eye.z) * (top-bottom)/(2*near)
- eye.z * (top+bottom)/(2*near) );
return eye;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment