depth_fetch.glslf 446 B

1234567891011121314151617
  1. #ifndef DEPTH_FETCH_GLSLF
  2. #define DEPTH_FETCH_GLSLF
  3. float depth_fetch(in sampler2D depth_tex, in vec2 coord, in vec2 cam_range) {
  4. float depth = GLSL_TEXTURE(depth_tex, coord).r;
  5. float near = cam_range.x;
  6. float far = cam_range.y;
  7. //float depth_linear = 2.0 * near / (near + far - depth * (far - near));
  8. float depth_linear = 2.0 * near / (near + far - (2.0 * depth - 1.0) * (far - near));
  9. return depth_linear;
  10. }
  11. #endif