luminance.glsl 442 B

1234567891011121314151617181920
  1. /**
  2. * Computes the luminance of a color.
  3. *
  4. * @name czm_luminance
  5. * @glslFunction
  6. *
  7. * @param {vec3} rgb The color.
  8. *
  9. * @returns {float} The luminance.
  10. *
  11. * @example
  12. * float light = czm_luminance(vec3(0.0)); // 0.0
  13. * float dark = czm_luminance(vec3(1.0)); // ~1.0
  14. */
  15. float czm_luminance(vec3 rgb)
  16. {
  17. // Algorithm from Chapter 10 of Graphics Shaders.
  18. const vec3 W = vec3(0.2125, 0.7154, 0.0721);
  19. return dot(rgb, W);
  20. }