sphericalHarmonics.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Computes a color from the third order spherical harmonic coefficients and a normalized direction vector.\n\
  4. * <p>\n\
  5. * The order of the coefficients is [L00, L1_1, L10, L11, L2_2, L2_1, L20, L21, L22].\n\
  6. * </p>\n\
  7. *\n\
  8. * @name czm_sphericalHarmonics\n\
  9. * @glslFunction\n\
  10. *\n\
  11. * @param {vec3} normal The normalized direction.\n\
  12. * @param {vec3[9]} coefficients The third order spherical harmonic coefficients.\n\
  13. * @returns {vec3} The color at the direction.\n\
  14. *\n\
  15. * @see https://graphics.stanford.edu/papers/envmap/envmap.pdf\n\
  16. */\n\
  17. vec3 czm_sphericalHarmonics(vec3 normal, vec3 coefficients[9])\n\
  18. {\n\
  19. const float c1 = 0.429043;\n\
  20. const float c2 = 0.511664;\n\
  21. const float c3 = 0.743125;\n\
  22. const float c4 = 0.886227;\n\
  23. const float c5 = 0.247708;\n\
  24. \n\
  25. vec3 L00 = coefficients[0];\n\
  26. vec3 L1_1 = coefficients[1];\n\
  27. vec3 L10 = coefficients[2];\n\
  28. vec3 L11 = coefficients[3];\n\
  29. vec3 L2_2 = coefficients[4];\n\
  30. vec3 L2_1 = coefficients[5];\n\
  31. vec3 L20 = coefficients[6];\n\
  32. vec3 L21 = coefficients[7];\n\
  33. vec3 L22 = coefficients[8];\n\
  34. \n\
  35. float x = normal.x;\n\
  36. float y = normal.y;\n\
  37. float z = normal.z;\n\
  38. \n\
  39. return c1 * L22 * (x * x - y * y) + c3 * L20 * z * z + c4 * L00 - c5 * L20 +\n\
  40. 2.0 * c1 * (L2_2 * x * y + L21 * x * z + L2_1 * y * z) +\n\
  41. 2.0 * c2 * (L11 * x + L1_1 * y + L10 * z);\n\
  42. }\n\
  43. ";