writeLogDepth.js 2.5 KB

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