vertexLogDepth.glsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifdef LOG_DEPTH
  2. varying float v_logZ;
  3. #ifdef SHADOW_MAP
  4. varying vec3 v_logPositionEC;
  5. #endif
  6. #endif
  7. void czm_updatePositionDepth() {
  8. #if defined(LOG_DEPTH) && !defined(DISABLE_GL_POSITION_LOG_DEPTH)
  9. vec3 logPositionEC = (czm_inverseProjection * gl_Position).xyz;
  10. #ifdef SHADOW_MAP
  11. v_logPositionEC = logPositionEC;
  12. #endif
  13. #ifdef ENABLE_GL_POSITION_LOG_DEPTH_AT_HEIGHT
  14. if (length(logPositionEC) < 2.0e6)
  15. {
  16. return;
  17. }
  18. #endif
  19. gl_Position.z = log2(max(1e-6, 1.0 + gl_Position.w)) * czm_log2FarDistance - 1.0;
  20. gl_Position.z *= gl_Position.w;
  21. #endif
  22. }
  23. /**
  24. * Writes the logarithmic depth to gl_Position using the already computed gl_Position.
  25. *
  26. * @name czm_vertexLogDepth
  27. * @glslFunction
  28. */
  29. void czm_vertexLogDepth()
  30. {
  31. #ifdef LOG_DEPTH
  32. v_logZ = 1.0 + gl_Position.w;
  33. czm_updatePositionDepth();
  34. #endif
  35. }
  36. /**
  37. * Writes the logarithmic depth to gl_Position using the provided clip coordinates.
  38. * <p>
  39. * An example use case for this function would be moving the vertex in window coordinates
  40. * before converting back to clip coordinates. Use the original vertex clip coordinates.
  41. * </p>
  42. * @name czm_vertexLogDepth
  43. * @glslFunction
  44. *
  45. * @param {vec4} clipCoords The vertex in clip coordinates.
  46. *
  47. * @example
  48. * czm_vertexLogDepth(czm_projection * vec4(positionEyeCoordinates, 1.0));
  49. */
  50. void czm_vertexLogDepth(vec4 clipCoords)
  51. {
  52. #ifdef LOG_DEPTH
  53. v_logZ = 1.0 + clipCoords.w;
  54. czm_updatePositionDepth();
  55. #endif
  56. }