SkyAtmosphereFS.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @license
  3. * Copyright (c) 2000-2005, Sean O'Neil (s_p_oneil@hotmail.com)
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * * Neither the name of the project nor the names of its contributors may be
  16. * used to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * Modifications made by Analytical Graphics, Inc.
  31. */
  32. //This file is automatically rebuilt by the Cesium build process.
  33. /*global define*/
  34. define(function() {
  35. "use strict";
  36. return "/**\n\
  37. * @license\n\
  38. * Copyright (c) 2000-2005, Sean O'Neil (s_p_oneil@hotmail.com)\n\
  39. * All rights reserved.\n\
  40. * \n\
  41. * Redistribution and use in source and binary forms, with or without\n\
  42. * modification, are permitted provided that the following conditions\n\
  43. * are met:\n\
  44. * \n\
  45. * * Redistributions of source code must retain the above copyright notice,\n\
  46. * this list of conditions and the following disclaimer.\n\
  47. * * Redistributions in binary form must reproduce the above copyright notice,\n\
  48. * this list of conditions and the following disclaimer in the documentation\n\
  49. * and/or other materials provided with the distribution.\n\
  50. * * Neither the name of the project nor the names of its contributors may be\n\
  51. * used to endorse or promote products derived from this software without\n\
  52. * specific prior written permission.\n\
  53. * \n\
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n\
  55. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
  56. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n\
  57. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n\
  58. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\
  59. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n\
  60. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n\
  61. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n\
  62. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
  63. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\
  64. *\n\
  65. * Modifications made by Analytical Graphics, Inc.\n\
  66. */\n\
  67. \n\
  68. // Code: http://sponeil.net/\n\
  69. // GPU Gems 2 Article: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html\n\
  70. \n\
  71. const float g = -0.95;\n\
  72. const float g2 = g * g;\n\
  73. \n\
  74. varying vec3 v_rayleighColor;\n\
  75. varying vec3 v_mieColor;\n\
  76. varying vec3 v_toCamera;\n\
  77. varying vec3 v_positionEC;\n\
  78. \n\
  79. void main (void)\n\
  80. {\n\
  81. // TODO: make arbitrary ellipsoid\n\
  82. czm_ellipsoid ellipsoid = czm_getWgs84EllipsoidEC();\n\
  83. \n\
  84. vec3 direction = normalize(v_positionEC);\n\
  85. czm_ray ray = czm_ray(vec3(0.0), direction);\n\
  86. \n\
  87. czm_raySegment intersection = czm_rayEllipsoidIntersectionInterval(ray, ellipsoid);\n\
  88. if (!czm_isEmpty(intersection)) {\n\
  89. discard;\n\
  90. }\n\
  91. \n\
  92. // Extra normalize added for Android\n\
  93. float fCos = dot(czm_sunDirectionWC, normalize(v_toCamera)) / length(v_toCamera);\n\
  94. float fRayleighPhase = 0.75 * (1.0 + fCos*fCos);\n\
  95. float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);\n\
  96. \n\
  97. const float fExposure = 2.0;\n\
  98. \n\
  99. vec3 rgb = fRayleighPhase * v_rayleighColor + fMiePhase * v_mieColor;\n\
  100. rgb = vec3(1.0) - exp(-fExposure * rgb);\n\
  101. float l = czm_luminance(rgb);\n\
  102. gl_FragColor = vec4(rgb, min(smoothstep(0.0, 0.1, l), 1.0) * smoothstep(0.0, 1.0, czm_morphTime));\n\
  103. }\n\
  104. ";
  105. });