SkyAtmosphereFS.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. export default "#ifdef COLOR_CORRECT\n\
  34. uniform vec3 u_hsbShift;\n\
  35. #endif\n\
  36. uniform vec4 u_cameraAndRadiiAndDynamicAtmosphereColor;\n\
  37. const float g = -0.95;\n\
  38. const float g2 = g * g;\n\
  39. varying vec3 v_rayleighColor;\n\
  40. varying vec3 v_mieColor;\n\
  41. varying vec3 v_toCamera;\n\
  42. varying vec3 v_positionEC;\n\
  43. void main (void)\n\
  44. {\n\
  45. float cosAngle = dot(czm_sunDirectionWC, normalize(v_toCamera)) / length(v_toCamera);\n\
  46. float rayleighPhase = 0.75 * (1.0 + cosAngle * cosAngle);\n\
  47. float miePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + cosAngle * cosAngle) / pow(1.0 + g2 - 2.0 * g * cosAngle, 1.5);\n\
  48. vec3 rgb = rayleighPhase * v_rayleighColor + miePhase * v_mieColor;\n\
  49. #ifndef HDR\n\
  50. const float exposure = 2.0;\n\
  51. rgb = vec3(1.0) - exp(-exposure * rgb);\n\
  52. #endif\n\
  53. #ifdef COLOR_CORRECT\n\
  54. vec3 hsb = czm_RGBToHSB(rgb);\n\
  55. hsb.x += u_hsbShift.x;\n\
  56. hsb.y = clamp(hsb.y + u_hsbShift.y, 0.0, 1.0);\n\
  57. hsb.z = hsb.z > czm_epsilon7 ? hsb.z + u_hsbShift.z : 0.0;\n\
  58. rgb = czm_HSBToRGB(hsb);\n\
  59. #endif\n\
  60. float atmosphereAlpha = clamp((u_cameraAndRadiiAndDynamicAtmosphereColor.y - u_cameraAndRadiiAndDynamicAtmosphereColor.x) / (u_cameraAndRadiiAndDynamicAtmosphereColor.y - u_cameraAndRadiiAndDynamicAtmosphereColor.z), 0.0, 1.0);\n\
  61. float nightAlpha = (u_cameraAndRadiiAndDynamicAtmosphereColor.w > 0.0) ? clamp(dot(normalize(czm_viewerPositionWC), normalize(czm_sunPositionWC)), 0.0, 1.0) : 1.0;\n\
  62. atmosphereAlpha *= pow(nightAlpha, 0.5);\n\
  63. gl_FragColor = vec4(rgb, mix(rgb.b, 1.0, atmosphereAlpha) * smoothstep(0.0, 1.0, czm_morphTime));\n\
  64. }\n\
  65. ";