SkyAtmosphereFS.glsl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. varying vec3 v_outerPositionWC;
  2. uniform vec3 u_hsbShift;
  3. #ifndef PER_FRAGMENT_ATMOSPHERE
  4. varying vec3 v_mieColor;
  5. varying vec3 v_rayleighColor;
  6. varying float v_opacity;
  7. varying float v_translucent;
  8. #endif
  9. void main (void)
  10. {
  11. vec3 lightDirection = getLightDirection(v_outerPositionWC);
  12. vec3 mieColor;
  13. vec3 rayleighColor;
  14. float opacity;
  15. float translucent;
  16. #ifdef PER_FRAGMENT_ATMOSPHERE
  17. computeAtmosphereScattering(
  18. v_outerPositionWC,
  19. lightDirection,
  20. rayleighColor,
  21. mieColor,
  22. opacity,
  23. translucent
  24. );
  25. #else
  26. mieColor = v_mieColor;
  27. rayleighColor = v_rayleighColor;
  28. opacity = v_opacity;
  29. translucent = v_translucent;
  30. #endif
  31. vec4 color = computeAtmosphereColor(v_outerPositionWC, lightDirection, rayleighColor, mieColor, opacity);
  32. #ifndef HDR
  33. color.rgb = czm_acesTonemapping(color.rgb);
  34. color.rgb = czm_inverseGamma(color.rgb);
  35. #endif
  36. #ifdef COLOR_CORRECT
  37. // Convert rgb color to hsb
  38. vec3 hsb = czm_RGBToHSB(color.rgb);
  39. // Perform hsb shift
  40. hsb.x += u_hsbShift.x; // hue
  41. hsb.y = clamp(hsb.y + u_hsbShift.y, 0.0, 1.0); // saturation
  42. hsb.z = hsb.z > czm_epsilon7 ? hsb.z + u_hsbShift.z : 0.0; // brightness
  43. // Convert shifted hsb back to rgb
  44. color.rgb = czm_HSBToRGB(hsb);
  45. #endif
  46. // For the parts of the sky atmosphere that are not behind a translucent globe,
  47. // we mix in the default opacity so that the sky atmosphere still appears at distance.
  48. // This is needed because the opacity in the sky atmosphere is initially adjusted based
  49. // on the camera height.
  50. if (translucent == 0.0) {
  51. color.a = mix(color.b, 1.0, color.a) * smoothstep(0.0, 1.0, czm_morphTime);
  52. }
  53. gl_FragColor = color;
  54. }