linearizedepth.frag 247 B

1234567891011121314
  1. uniform sampler2D tex;
  2. uniform float zn;
  3. uniform float zf;
  4. out float Depth;
  5. void main()
  6. {
  7. vec2 uv = gl_FragCoord.xy / screen;
  8. float d = texture(tex, uv).x;
  9. float c0 = zn * zf, c1 = zn - zf, c2 = zf;
  10. Depth = c0 / (d * c1 + c2);
  11. }