RGBToHSL.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Converts an RGB color to HSL (hue, saturation, lightness)\n\
  4. * HSL <-> RGB conversion: {@link http://www.chilliant.com/rgb2hsv.html}\n\
  5. *\n\
  6. * @name czm_RGBToHSL\n\
  7. * @glslFunction\n\
  8. * \n\
  9. * @param {vec3} rgb The color in RGB.\n\
  10. *\n\
  11. * @returns {vec3} The color in HSL.\n\
  12. *\n\
  13. * @example\n\
  14. * vec3 hsl = czm_RGBToHSL(rgb);\n\
  15. * hsl.z *= 0.1;\n\
  16. * rgb = czm_HSLToRGB(hsl);\n\
  17. */\n\
  18. \n\
  19. vec3 RGBtoHCV(vec3 rgb)\n\
  20. {\n\
  21. // Based on work by Sam Hocevar and Emil Persson\n\
  22. vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0);\n\
  23. vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);\n\
  24. float c = q.x - min(q.w, q.y);\n\
  25. float h = abs((q.w - q.y) / (6.0 * c + czm_epsilon7) + q.z);\n\
  26. return vec3(h, c, q.x);\n\
  27. }\n\
  28. \n\
  29. vec3 czm_RGBToHSL(vec3 rgb)\n\
  30. {\n\
  31. vec3 hcv = RGBtoHCV(rgb);\n\
  32. float l = hcv.z - hcv.y * 0.5;\n\
  33. float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + czm_epsilon7);\n\
  34. return vec3(hcv.x, s, l);\n\
  35. }\n\
  36. ";