writeLogDepth.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef LOG_DEPTH\n\
  3. varying float v_depthFromNearPlusOne;\n\
  4. \n\
  5. #ifdef POLYGON_OFFSET\n\
  6. uniform vec2 u_polygonOffset;\n\
  7. #endif\n\
  8. \n\
  9. #endif\n\
  10. \n\
  11. /**\n\
  12. * Writes the fragment depth to the logarithmic depth buffer.\n\
  13. * <p>\n\
  14. * Use this when the vertex shader does not call {@link czm_vertexlogDepth}, for example, when\n\
  15. * ray-casting geometry using a full screen quad.\n\
  16. * </p>\n\
  17. * @name czm_writeLogDepth\n\
  18. * @glslFunction\n\
  19. *\n\
  20. * @param {float} depth The depth coordinate, where 1.0 is on the near plane and\n\
  21. * depth increases in eye-space units from there\n\
  22. *\n\
  23. * @example\n\
  24. * czm_writeLogDepth((czm_projection * v_positionEyeCoordinates).w + 1.0);\n\
  25. */\n\
  26. void czm_writeLogDepth(float depth)\n\
  27. {\n\
  28. #if defined(GL_EXT_frag_depth) && defined(LOG_DEPTH)\n\
  29. // Discard the vertex if it's not between the near and far planes.\n\
  30. // We allow a bit of epsilon on the near plane comparison because a 1.0\n\
  31. // from the vertex shader (indicating the vertex should be _on_ the near\n\
  32. // plane) will not necessarily come here as exactly 1.0.\n\
  33. if (depth <= 0.9999999 || depth > czm_farDepthFromNearPlusOne) {\n\
  34. discard;\n\
  35. }\n\
  36. \n\
  37. #ifdef POLYGON_OFFSET\n\
  38. // Polygon offset: m * factor + r * units\n\
  39. float factor = u_polygonOffset[0];\n\
  40. float units = u_polygonOffset[1];\n\
  41. \n\
  42. // If we can't compute derivatives, just leave out the factor I guess?\n\
  43. #ifdef GL_OES_standard_derivatives\n\
  44. // m = sqrt(dZdX^2 + dZdY^2);\n\
  45. float x = dFdx(depth);\n\
  46. float y = dFdy(depth);\n\
  47. float m = sqrt(x * x + y * y);\n\
  48. \n\
  49. // Apply the factor before computing the log depth.\n\
  50. depth += m * factor;\n\
  51. #endif\n\
  52. \n\
  53. #endif\n\
  54. \n\
  55. gl_FragDepthEXT = log2(depth) * czm_oneOverLog2FarDepthFromNearPlusOne;\n\
  56. \n\
  57. #ifdef POLYGON_OFFSET\n\
  58. // Apply the units after the log depth.\n\
  59. gl_FragDepthEXT += czm_epsilon7 * units;\n\
  60. #endif\n\
  61. \n\
  62. #endif\n\
  63. }\n\
  64. \n\
  65. /**\n\
  66. * Writes the fragment depth to the logarithmic depth buffer.\n\
  67. * <p>\n\
  68. * Use this when the vertex shader calls {@link czm_vertexlogDepth}.\n\
  69. * </p>\n\
  70. *\n\
  71. * @name czm_writeLogDepth\n\
  72. * @glslFunction\n\
  73. */\n\
  74. void czm_writeLogDepth() {\n\
  75. #ifdef LOG_DEPTH\n\
  76. czm_writeLogDepth(v_depthFromNearPlusOne);\n\
  77. #endif\n\
  78. }\n\
  79. ";