LinearDepth.glsl 500 B

1234567891011121314151617
  1. // Copyright (C) 2009-2016, 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. // This is the optimal linearizeDepth where a=(f+n)/2n and b=(n-f)/2n
  11. float linearizeDepthOptimal(in float depth, in float a, in float b)
  12. {
  13. return 1.0 / (a + depth * b);
  14. }