writeLogDepth.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifdef LOG_DEPTH
  2. varying float v_logZ;
  3. #endif
  4. /**
  5. * Writes the fragment depth to the logarithmic depth buffer.
  6. * <p>
  7. * Use this when the vertex shader does not call {@link czm_vertexlogDepth}, for example, when
  8. * ray-casting geometry using a full screen quad.
  9. * </p>
  10. * @name czm_writeLogDepth
  11. * @glslFunction
  12. *
  13. * @param {float} logZ The w coordinate of the vertex in clip coordinates plus 1.0.
  14. *
  15. * @example
  16. * czm_writeLogDepth((czm_projection * v_positionEyeCoordinates).w + 1.0);
  17. */
  18. void czm_writeLogDepth(float logZ)
  19. {
  20. #if defined(GL_EXT_frag_depth) && defined(LOG_DEPTH) && !defined(DISABLE_LOG_DEPTH_FRAGMENT_WRITE)
  21. float halfLogFarDistance = czm_log2FarDistance * 0.5;
  22. float depth = log2(logZ);
  23. if (depth < czm_log2NearDistance) {
  24. discard;
  25. }
  26. gl_FragDepthEXT = depth * halfLogFarDistance;
  27. #endif
  28. }
  29. /**
  30. * Writes the fragment depth to the logarithmic depth buffer.
  31. * <p>
  32. * Use this when the vertex shader calls {@link czm_vertexlogDepth}.
  33. * </p>
  34. *
  35. * @name czm_writeLogDepth
  36. * @glslFunction
  37. */
  38. void czm_writeLogDepth() {
  39. #ifdef LOG_DEPTH
  40. czm_writeLogDepth(v_logZ);
  41. #endif
  42. }