sphericalHarmonics.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Computes a color from the third order spherical harmonic coefficients and a normalized direction vector.
  3. * <p>
  4. * The order of the coefficients is [L00, L1_1, L10, L11, L2_2, L2_1, L20, L21, L22].
  5. * </p>
  6. *
  7. * @name czm_sphericalHarmonics
  8. * @glslFunction
  9. *
  10. * @param {vec3} normal The normalized direction.
  11. * @param {vec3[9]} coefficients The third order spherical harmonic coefficients.
  12. * @returns {vec3} The color at the direction.
  13. *
  14. * @see https://graphics.stanford.edu/papers/envmap/envmap.pdf
  15. */
  16. vec3 czm_sphericalHarmonics(vec3 normal, vec3 coefficients[9])
  17. {
  18. vec3 L00 = coefficients[0];
  19. vec3 L1_1 = coefficients[1];
  20. vec3 L10 = coefficients[2];
  21. vec3 L11 = coefficients[3];
  22. vec3 L2_2 = coefficients[4];
  23. vec3 L2_1 = coefficients[5];
  24. vec3 L20 = coefficients[6];
  25. vec3 L21 = coefficients[7];
  26. vec3 L22 = coefficients[8];
  27. float x = normal.x;
  28. float y = normal.y;
  29. float z = normal.z;
  30. return
  31. L00
  32. + L1_1 * y
  33. + L10 * z
  34. + L11 * x
  35. + L2_2 * (y * x)
  36. + L2_1 * (y * z)
  37. + L20 * (3.0 * z * z - 1.0)
  38. + L21 * (z * x)
  39. + L22 * (x * x - y * y);
  40. }