智慧水务管理系统 - 精河县供水工程综合管理平台

ComputeRadianceMapFS.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "precision highp float;\n\
  3. \n\
  4. in vec2 v_textureCoordinates;\n\
  5. \n\
  6. uniform vec3 u_faceDirection; // Current cubemap face\n\
  7. uniform vec3 u_positionWC;\n\
  8. uniform mat4 u_enuToFixedFrame;\n\
  9. uniform vec4 u_brightnessSaturationGammaIntensity;\n\
  10. uniform vec4 u_groundColor; // alpha component represent albedo\n\
  11. \n\
  12. vec4 getCubeMapDirection(vec2 uv, vec3 faceDir) {\n\
  13. vec2 scaledUV = uv * 2.0 - 1.0;\n\
  14. \n\
  15. if (faceDir.x != 0.0) {\n\
  16. return vec4(faceDir.x, scaledUV.x * faceDir.x, -scaledUV.y, 0.0);\n\
  17. } else if (faceDir.y != 0.0) {\n\
  18. return vec4(scaledUV.x, -scaledUV.y * faceDir.y, faceDir.y, 0.0);\n\
  19. } else {\n\
  20. return vec4(scaledUV.x * faceDir.z, -faceDir.z, -scaledUV.y, 0.0); \n\
  21. }\n\
  22. }\n\
  23. \n\
  24. void main() { \n\
  25. float height = length(u_positionWC);\n\
  26. float atmosphereInnerRadius = u_radiiAndDynamicAtmosphereColor.y;\n\
  27. float ellipsoidHeight = max(height - atmosphereInnerRadius, 0.0);\n\
  28. \n\
  29. // Scale the position to ensure the sky color is present, even when underground.\n\
  30. vec3 positionWC = u_positionWC / height * (ellipsoidHeight + atmosphereInnerRadius);\n\
  31. \n\
  32. float atmosphereOuterRadius = u_radiiAndDynamicAtmosphereColor.x;\n\
  33. float atmosphereHeight = atmosphereOuterRadius - atmosphereInnerRadius;\n\
  34. \n\
  35. vec3 direction = (u_enuToFixedFrame * getCubeMapDirection(v_textureCoordinates, u_faceDirection)).xyz;\n\
  36. vec3 normalizedDirection = normalize(direction);\n\
  37. \n\
  38. czm_ray ray = czm_ray(positionWC, normalizedDirection);\n\
  39. czm_raySegment intersection = czm_raySphereIntersectionInterval(ray, vec3(0.0), atmosphereInnerRadius);\n\
  40. if (!czm_isEmpty(intersection)) {\n\
  41. intersection = czm_rayEllipsoidIntersectionInterval(ray, vec3(0.0), czm_ellipsoidInverseRadii);\n\
  42. }\n\
  43. \n\
  44. bool onEllipsoid = intersection.start >= 0.0;\n\
  45. float rayLength = czm_branchFreeTernary(onEllipsoid, intersection.start, atmosphereOuterRadius);\n\
  46. \n\
  47. // Compute sky color for each position on a sphere at radius centered around the provided position's origin\n\
  48. vec3 skyPositionWC = positionWC + normalizedDirection * rayLength;\n\
  49. \n\
  50. float lightEnum = u_radiiAndDynamicAtmosphereColor.z;\n\
  51. vec3 lightDirectionWC = normalize(czm_getDynamicAtmosphereLightDirection(skyPositionWC, lightEnum));\n\
  52. vec3 mieColor;\n\
  53. vec3 rayleighColor;\n\
  54. float opacity;\n\
  55. czm_computeScattering(\n\
  56. ray,\n\
  57. rayLength,\n\
  58. lightDirectionWC,\n\
  59. atmosphereInnerRadius, \n\
  60. rayleighColor,\n\
  61. mieColor,\n\
  62. opacity\n\
  63. );\n\
  64. \n\
  65. vec4 atmopshereColor = czm_computeAtmosphereColor(ray, lightDirectionWC, rayleighColor, mieColor, opacity);\n\
  66. \n\
  67. #ifdef ATMOSPHERE_COLOR_CORRECT\n\
  68. const bool ignoreBlackPixels = true;\n\
  69. atmopshereColor.rgb = czm_applyHSBShift(atmopshereColor.rgb, czm_atmosphereHsbShift, ignoreBlackPixels);\n\
  70. #endif\n\
  71. \n\
  72. vec3 lookupDirection = -normalizedDirection;\n\
  73. // Flipping the X vector is a cheap way to get the inverse of czm_temeToPseudoFixed, since that's a rotation about Z.\n\
  74. lookupDirection.x = -lookupDirection.x;\n\
  75. lookupDirection = -normalize(czm_temeToPseudoFixed * lookupDirection);\n\
  76. lookupDirection.x = -lookupDirection.x;\n\
  77. \n\
  78. // Values outside the atmopshere are rendered as black, when they should be treated as transparent\n\
  79. float skyAlpha = clamp((1.0 - ellipsoidHeight / atmosphereHeight) * atmopshereColor.a, 0.0, 1.0);\n\
  80. skyAlpha = czm_branchFreeTernary(length(atmopshereColor.rgb) <= czm_epsilon7, 0.0, skyAlpha); // Treat black as transparent\n\
  81. \n\
  82. // Blend starmap with atmopshere scattering\n\
  83. float intensity = u_brightnessSaturationGammaIntensity.w;\n\
  84. vec4 sceneSkyBoxColor = czm_textureCube(czm_environmentMap, lookupDirection);\n\
  85. vec3 skyBackgroundColor = mix(czm_backgroundColor.rgb, sceneSkyBoxColor.rgb, sceneSkyBoxColor.a);\n\
  86. vec4 combinedSkyColor = vec4(mix(skyBackgroundColor, atmopshereColor.rgb * intensity, skyAlpha), 1.0);\n\
  87. \n\
  88. // Compute ground color based on amount of reflected light, then blend it with ground atmosphere based on height\n\
  89. vec3 up = normalize(positionWC);\n\
  90. float occlusion = max(dot(lightDirectionWC, up), 0.05);\n\
  91. vec4 groundColor = vec4(u_groundColor.rgb * u_groundColor.a * (vec3(intensity * occlusion) + atmopshereColor.rgb), 1.0);\n\
  92. vec4 blendedGroundColor = mix(groundColor, atmopshereColor, clamp(ellipsoidHeight / atmosphereHeight, 0.0, 1.0));\n\
  93. \n\
  94. vec4 color = czm_branchFreeTernary(onEllipsoid, blendedGroundColor, combinedSkyColor);\n\
  95. \n\
  96. float brightness = u_brightnessSaturationGammaIntensity.x;\n\
  97. float saturation = u_brightnessSaturationGammaIntensity.y;\n\
  98. float gamma = u_brightnessSaturationGammaIntensity.z;\n\
  99. \n\
  100. #ifdef ENVIRONMENT_COLOR_CORRECT\n\
  101. color.rgb = mix(vec3(0.0), color.rgb, brightness);\n\
  102. color.rgb = czm_saturation(color.rgb, saturation);\n\
  103. #endif\n\
  104. color.rgb = pow(color.rgb, vec3(gamma)); // Normally this would be in the ifdef above, but there is a precision issue with the atmopshere scattering transmittance (alpha). Having this line is a workaround for that issue, even when gamma is 1.0.\n\
  105. color.rgb = czm_gammaCorrect(color.rgb);\n\
  106. \n\
  107. out_FragColor = color;\n\
  108. }\n\
  109. ";