depthClamp.glsl 626 B

123456789101112131415161718192021222324252627
  1. // emulated noperspective
  2. #ifndef LOG_DEPTH
  3. varying float v_WindowZ;
  4. #endif
  5. /**
  6. * Clamps a vertex to the near and far planes.
  7. *
  8. * @name czm_depthClamp
  9. * @glslFunction
  10. *
  11. * @param {vec4} coords The vertex in clip coordinates.
  12. * @returns {vec4} The vertex clipped to the near and far planes.
  13. *
  14. * @example
  15. * gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));
  16. *
  17. * @see czm_writeDepthClamp
  18. */
  19. vec4 czm_depthClamp(vec4 coords)
  20. {
  21. #ifndef LOG_DEPTH
  22. v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;
  23. coords.z = clamp(coords.z, -coords.w, +coords.w);
  24. #endif
  25. return coords;
  26. }