tangentToEyeSpaceMatrix.glsl 960 B

12345678910111213141516171819202122232425
  1. /**
  2. * Creates a matrix that transforms vectors from tangent space to eye space.
  3. *
  4. * @name czm_tangentToEyeSpaceMatrix
  5. * @glslFunction
  6. *
  7. * @param {vec3} normalEC The normal vector in eye coordinates.
  8. * @param {vec3} tangentEC The tangent vector in eye coordinates.
  9. * @param {vec3} bitangentEC The bitangent vector in eye coordinates.
  10. *
  11. * @returns {mat3} The matrix that transforms from tangent space to eye space.
  12. *
  13. * @example
  14. * mat3 tangentToEye = czm_tangentToEyeSpaceMatrix(normalEC, tangentEC, bitangentEC);
  15. * vec3 normal = tangentToEye * texture(normalMap, st).xyz;
  16. */
  17. mat3 czm_tangentToEyeSpaceMatrix(vec3 normalEC, vec3 tangentEC, vec3 bitangentEC)
  18. {
  19. vec3 normal = normalize(normalEC);
  20. vec3 tangent = normalize(tangentEC);
  21. vec3 bitangent = normalize(bitangentEC);
  22. return mat3(tangent.x , tangent.y , tangent.z,
  23. bitangent.x, bitangent.y, bitangent.z,
  24. normal.x , normal.y , normal.z);
  25. }