hue.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Adjusts the hue of a color.\n\
  4. * \n\
  5. * @name czm_hue\n\
  6. * @glslFunction\n\
  7. * \n\
  8. * @param {vec3} rgb The color.\n\
  9. * @param {float} adjustment The amount to adjust the hue of the color in radians.\n\
  10. *\n\
  11. * @returns {float} The color with the hue adjusted.\n\
  12. *\n\
  13. * @example\n\
  14. * vec3 adjustHue = czm_hue(color, czm_pi); // The same as czm_hue(color, -czm_pi)\n\
  15. */\n\
  16. vec3 czm_hue(vec3 rgb, float adjustment)\n\
  17. {\n\
  18. const mat3 toYIQ = mat3(0.299, 0.587, 0.114,\n\
  19. 0.595716, -0.274453, -0.321263,\n\
  20. 0.211456, -0.522591, 0.311135);\n\
  21. const mat3 toRGB = mat3(1.0, 0.9563, 0.6210,\n\
  22. 1.0, -0.2721, -0.6474,\n\
  23. 1.0, -1.107, 1.7046);\n\
  24. \n\
  25. vec3 yiq = toYIQ * rgb;\n\
  26. float hue = atan(yiq.z, yiq.y) + adjustment;\n\
  27. float chroma = sqrt(yiq.z * yiq.z + yiq.y * yiq.y);\n\
  28. \n\
  29. vec3 color = vec3(yiq.x, chroma * cos(hue), chroma * sin(hue));\n\
  30. return toRGB * color;\n\
  31. }\n\
  32. ";