fog.glsl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Gets the color with fog at a distance from the camera.
  3. *
  4. * @name czm_fog
  5. * @glslFunction
  6. *
  7. * @param {float} distanceToCamera The distance to the camera in meters.
  8. * @param {vec3} color The original color.
  9. * @param {vec3} fogColor The color of the fog.
  10. *
  11. * @returns {vec3} The color adjusted for fog at the distance from the camera.
  12. */
  13. vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor)
  14. {
  15. float scalar = distanceToCamera * czm_fogDensity;
  16. float fog = 1.0 - exp(-(scalar * scalar));
  17. return mix(color, fogColor, fog);
  18. }
  19. /**
  20. * Gets the color with fog at a distance from the camera.
  21. *
  22. * @name czm_fog
  23. * @glslFunction
  24. *
  25. * @param {float} distanceToCamera The distance to the camera in meters.
  26. * @param {vec3} color The original color.
  27. * @param {vec3} fogColor The color of the fog.
  28. * @param {float} fogModifierConstant A constant to modify the appearance of fog.
  29. *
  30. * @returns {vec3} The color adjusted for fog at the distance from the camera.
  31. */
  32. vec3 czm_fog(float distanceToCamera, vec3 color, vec3 fogColor, float fogModifierConstant)
  33. {
  34. float scalar = distanceToCamera * czm_fogDensity;
  35. float fog = 1.0 - exp(-((fogModifierConstant * scalar + fogModifierConstant) * (scalar * (1.0 + fogModifierConstant))));
  36. return mix(color, fogColor, fog);
  37. }