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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. float interpolateByDistance(vec4 nearFarScalar, float distance)
  2. {
  3. float startDistance = nearFarScalar.x;
  4. float startValue = nearFarScalar.y;
  5. float endDistance = nearFarScalar.z;
  6. float endValue = nearFarScalar.w;
  7. float t = clamp((distance - startDistance) / (endDistance - startDistance), 0.0, 1.0);
  8. return mix(startValue, endValue, t);
  9. }
  10. void computeAtmosphereScattering(vec3 positionWC, vec3 lightDirection, out vec3 rayleighColor, out vec3 mieColor, out float opacity, out float underTranslucentGlobe)
  11. {
  12. float ellipsoidRadiiDifference = czm_ellipsoidRadii.x - czm_ellipsoidRadii.z;
  13. // Adjustment to the atmosphere radius applied based on the camera height.
  14. float distanceAdjustMin = czm_ellipsoidRadii.x / 4.0;
  15. float distanceAdjustMax = czm_ellipsoidRadii.x;
  16. float distanceAdjustModifier = ellipsoidRadiiDifference / 2.0;
  17. float distanceAdjust = distanceAdjustModifier * clamp((czm_eyeHeight - distanceAdjustMin) / (distanceAdjustMax - distanceAdjustMin), 0.0, 1.0);
  18. // Since atmosphere scattering assumes the atmosphere is a spherical shell, we compute an inner radius of the atmosphere best fit
  19. // for the position on the ellipsoid.
  20. float radiusAdjust = (ellipsoidRadiiDifference / 4.0) + distanceAdjust;
  21. float atmosphereInnerRadius = (length(czm_viewerPositionWC) - czm_eyeHeight) - radiusAdjust;
  22. // Setup the primary ray: from the camera position to the vertex position.
  23. vec3 cameraToPositionWC = positionWC - czm_viewerPositionWC;
  24. vec3 cameraToPositionWCDirection = normalize(cameraToPositionWC);
  25. czm_ray primaryRay = czm_ray(czm_viewerPositionWC, cameraToPositionWCDirection);
  26. underTranslucentGlobe = 0.0;
  27. // Brighten the sky atmosphere under the Earth's atmosphere when translucency is enabled.
  28. #if defined(GLOBE_TRANSLUCENT)
  29. // Check for intersection with the inner radius of the atmopshere.
  30. czm_raySegment primaryRayEarthIntersect = czm_raySphereIntersectionInterval(primaryRay, vec3(0.0), atmosphereInnerRadius + radiusAdjust);
  31. if (primaryRayEarthIntersect.start > 0.0 && primaryRayEarthIntersect.stop > 0.0) {
  32. // Compute position on globe.
  33. vec3 direction = normalize(positionWC);
  34. czm_ray ellipsoidRay = czm_ray(positionWC, -direction);
  35. czm_raySegment ellipsoidIntersection = czm_rayEllipsoidIntersectionInterval(ellipsoidRay, vec3(0.0), czm_ellipsoidInverseRadii);
  36. vec3 onEarth = positionWC - (direction * ellipsoidIntersection.start);
  37. // Control the color using the camera angle.
  38. float angle = dot(normalize(czm_viewerPositionWC), normalize(onEarth));
  39. // Control the opacity using the distance from Earth.
  40. opacity = interpolateByDistance(vec4(0.0, 1.0, czm_ellipsoidRadii.x, 0.0), length(czm_viewerPositionWC - onEarth));
  41. vec3 horizonColor = vec3(0.1, 0.2, 0.3);
  42. vec3 nearColor = vec3(0.0);
  43. rayleighColor = mix(nearColor, horizonColor, exp(-angle) * opacity);
  44. // Set the traslucent flag to avoid alpha adjustment in computeFinalColor funciton.
  45. underTranslucentGlobe = 1.0;
  46. return;
  47. }
  48. #endif
  49. computeScattering(
  50. primaryRay,
  51. length(cameraToPositionWC),
  52. lightDirection,
  53. atmosphereInnerRadius,
  54. rayleighColor,
  55. mieColor,
  56. opacity
  57. );
  58. // Alter the opacity based on how close the viewer is to the ground.
  59. // (0.0 = At edge of atmosphere, 1.0 = On ground)
  60. float cameraHeight = czm_eyeHeight + atmosphereInnerRadius;
  61. float atmosphereOuterRadius = atmosphereInnerRadius + ATMOSPHERE_THICKNESS;
  62. opacity = clamp((atmosphereOuterRadius - cameraHeight) / (atmosphereOuterRadius - atmosphereInnerRadius), 0.0, 1.0);
  63. // Alter alpha based on time of day (0.0 = night , 1.0 = day)
  64. float nightAlpha = (u_radiiAndDynamicAtmosphereColor.z != 0.0) ? clamp(dot(normalize(positionWC), lightDirection), 0.0, 1.0) : 1.0;
  65. opacity *= pow(nightAlpha, 0.5);
  66. }