approximateSphericalCoordinates.glsl 805 B

123456789101112131415161718
  1. /**
  2. * Approximately computes spherical coordinates given a normal.
  3. * Uses approximate inverse trigonometry for speed and consistency,
  4. * since inverse trigonometry can differ from vendor-to-vendor and when compared with the CPU.
  5. *
  6. * @name czm_approximateSphericalCoordinates
  7. * @glslFunction
  8. *
  9. * @param {vec3} normal arbitrary-length normal.
  10. *
  11. * @returns {vec2} Approximate latitude and longitude spherical coordinates.
  12. */
  13. vec2 czm_approximateSphericalCoordinates(vec3 normal) {
  14. // Project into plane with vertical for latitude
  15. float latitudeApproximation = czm_fastApproximateAtan(sqrt(normal.x * normal.x + normal.y * normal.y), normal.z);
  16. float longitudeApproximation = czm_fastApproximateAtan(normal.x, normal.y);
  17. return vec2(latitudeApproximation, longitudeApproximation);
  18. }