cameraNormalMatrix
A special mat3 matrix used to correctly transform a model's normal vector from model space to view space. It solves the issue of normal deformation under non-uniform scaling by being the 'inverse transpose' of the model-view matrix, ensuring physically correct lighting calculations.
Core Advantages
It automatically guarantees the correctness of lighting calculations. Developers are freed from manually computing and passing the complex inverse transpose matrix (the normal matrix) and don't need to track model or camera transforms. TSL handles this automatically, greatly simplifying the creation of custom lighting shaders.
Common Uses
Calculating view-space normals in classic lighting models (e.g., Blinn-Phong) for diffuse and specular components.
Providing the correct surface normal for environment reflection/refraction calculations to achieve accurate environment map sampling.
Enabling precise outline detection in toon shading (where the normal is perpendicular to the view direction).
Serving as a basis in normal mapping to transform tangent-space normals to view space.
Transforming dynamically generated normals from procedural displacement (e.g., water waves) for correct lighting.
How to adjust
This node's value cannot be directly adjusted for artistic effects; it is passively determined by model and camera transformations. Its effect is best understood through comparison: when a model is non-uniformly scaled (e.g., a sphere is squashed), using this node maintains natural and correct lighting. If another matrix (like modelViewMatrix) is mistakenly used, the lighting will appear distorted and misaligned with the model's surface contour.
Code Examples
1/* Correctly transform the normal from model space to view space */
2const viewNormal = cameraNormalMatrix.mul( objectNormal ).normalize();