Created
January 15, 2018 14:32
-
-
Save recp/d3121fe0629251b93e426c210ba9acbf to your computer and use it in GitHub Desktop.
OpenGL
This file contains hidden or 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
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