SHARE
TWEET

Untitled

a guest Dec 27th, 2014 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //FRAGMENT SHADER
  2.  
  3. float linearizeDepth(float depth) {    
  4.         return (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
  5. }
  6.  
  7. vec3 uvToEye(vec3 p) {
  8.         //vec2 pos = p * 2.0f - 1.0f;
  9.         //vec4 clipPos = vec4(p, z, 1.0f);
  10.         //vec4 viewPos = inverse(projection) * clipPos;
  11.         //return viewPos.xyz / viewPos.w;
  12.        
  13.         vec4 pos = inverse(projection) * vec4(p * 2 - 1, 1);
  14.         pos /= pos.w;
  15.         pos = inverse(mView) * pos;
  16.         return pos.xyz / pos.w;
  17. }
  18.  
  19. void main() {
  20.     float depth = texture(depthMap, coord).x;
  21.     depth = linearizeDepth(depth);
  22.     if (depth >= .99f) {
  23.         discard;
  24.         return;
  25.      }
  26.    
  27.     vec3 pos = uvToEye(vec3(coord, depth));
  28.  
  29.     //doing lots of other stuff that isn't relevant
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top