depthClamp.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "// emulated noperspective\n\
  3. #if (__VERSION__ == 300 || defined(GL_EXT_frag_depth)) && !defined(LOG_DEPTH)\n\
  4. out float v_WindowZ;\n\
  5. #endif\n\
  6. \n\
  7. /**\n\
  8. * Emulates GL_DEPTH_CLAMP, which is not available in WebGL 1 or 2.\n\
  9. * GL_DEPTH_CLAMP clamps geometry that is outside the near and far planes, \n\
  10. * capping the shadow volume. More information here: \n\
  11. * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_depth_clamp.txt.\n\
  12. *\n\
  13. * When GL_EXT_frag_depth is available we emulate GL_DEPTH_CLAMP by ensuring \n\
  14. * no geometry gets clipped by setting the clip space z value to 0.0 and then\n\
  15. * sending the unaltered screen space z value (using emulated noperspective\n\
  16. * interpolation) to the frag shader where it is clamped to [0,1] and then\n\
  17. * written with gl_FragDepth (see czm_writeDepthClamp). This technique is based on:\n\
  18. * https://stackoverflow.com/questions/5960757/how-to-emulate-gl-depth-clamp-nv.\n\
  19. *\n\
  20. * When GL_EXT_frag_depth is not available, which is the case on some mobile \n\
  21. * devices, we must attempt to fix this only in the vertex shader. \n\
  22. * The approach is to clamp the z value to the far plane, which closes the \n\
  23. * shadow volume but also distorts the geometry, so there can still be artifacts\n\
  24. * on frustum seams.\n\
  25. *\n\
  26. * @name czm_depthClamp\n\
  27. * @glslFunction\n\
  28. *\n\
  29. * @param {vec4} coords The vertex in clip coordinates.\n\
  30. * @returns {vec4} The modified vertex.\n\
  31. *\n\
  32. * @example\n\
  33. * gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));\n\
  34. *\n\
  35. * @see czm_writeDepthClamp\n\
  36. */\n\
  37. vec4 czm_depthClamp(vec4 coords)\n\
  38. {\n\
  39. #ifndef LOG_DEPTH\n\
  40. #if __VERSION__ == 300 || defined(GL_EXT_frag_depth)\n\
  41. v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;\n\
  42. coords.z = 0.0;\n\
  43. #else\n\
  44. coords.z = min(coords.z, coords.w);\n\
  45. #endif\n\
  46. #endif\n\
  47. return coords;\n\
  48. }\n\
  49. ";