RGBToXYZ.glsl 809 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Converts an RGB color to CIE Yxy.
  3. * <p>The conversion is described in
  4. * {@link http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering#Luminance_Transform|Luminance Transform}
  5. * </p>
  6. *
  7. * @name czm_RGBToXYZ
  8. * @glslFunction
  9. *
  10. * @param {vec3} rgb The color in RGB.
  11. *
  12. * @returns {vec3} The color in CIE Yxy.
  13. *
  14. * @example
  15. * vec3 xyz = czm_RGBToXYZ(rgb);
  16. * xyz.x = max(xyz.x - luminanceThreshold, 0.0);
  17. * rgb = czm_XYZToRGB(xyz);
  18. */
  19. vec3 czm_RGBToXYZ(vec3 rgb)
  20. {
  21. const mat3 RGB2XYZ = mat3(0.4124, 0.2126, 0.0193,
  22. 0.3576, 0.7152, 0.1192,
  23. 0.1805, 0.0722, 0.9505);
  24. vec3 xyz = RGB2XYZ * rgb;
  25. vec3 Yxy;
  26. Yxy.r = xyz.g;
  27. float temp = dot(vec3(1.0), xyz);
  28. Yxy.gb = xyz.rg / temp;
  29. return Yxy;
  30. }