saturation.glsl 632 B

12345678910111213141516171819202122
  1. /**
  2. * Adjusts the saturation of a color.
  3. *
  4. * @name czm_saturation
  5. * @glslFunction
  6. *
  7. * @param {vec3} rgb The color.
  8. * @param {float} adjustment The amount to adjust the saturation of the color.
  9. *
  10. * @returns {float} The color with the saturation adjusted.
  11. *
  12. * @example
  13. * vec3 greyScale = czm_saturation(color, 0.0);
  14. * vec3 doubleSaturation = czm_saturation(color, 2.0);
  15. */
  16. vec3 czm_saturation(vec3 rgb, float adjustment)
  17. {
  18. // Algorithm from Chapter 16 of OpenGL Shading Language
  19. const vec3 W = vec3(0.2125, 0.7154, 0.0721);
  20. vec3 intensity = vec3(dot(rgb, W));
  21. return mix(intensity, rgb, adjustment);
  22. }