LinearDepth.glsl 512 B

1234567891011121314151617
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // convert to linear depth
  6. float linearizeDepth(in float depth, in float zNear, in float zFar)
  7. {
  8. return (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
  9. }
  10. float readFromTextureAndLinearizeDepth(in sampler2D depthMap, in vec2 texCoord,
  11. in float zNear, in float zFar)
  12. {
  13. return linearizeDepth(texture(depthMap, texCoord).r, zNear, zFar);
  14. }