modelNormalMatrix
A mat3 matrix that correctly transforms normal vectors from model space to world space. It automatically handles non-uniform scaling to ensure physically correct lighting calculations.
Core Advantages
It completely encapsulates the complex 'inverse transpose matrix' calculation, freeing developers from the underlying math. It automatically and efficiently computes the correct normal matrix for each object on the CPU, avoiding expensive matrix inverse operations on the GPU, while keeping shader code clean and semantic.
Common Uses
Standard Lighting Models (PBR/Phong): To calculate the world-space normal, which is the foundation for all lighting computations.
Normal Mapping: To construct the TBN matrix for transforming tangent-space normals into world space.
Fresnel Effect & Rim Lighting: To calculate the angle between the surface normal and the view direction to determine the effect's intensity.
Toon Shading & Outlines: To provide an accurate world normal for light quantization and outline detection.
How to adjust
This node has no direct parameters to adjust. Its value is passively determined by the rendered object's transform (especially its scale). To observe its effect, apply non-uniform scaling to a lit object (e.g., `object.scale.set(2, 0.5, 1)`). Using `modelNormalMatrix` ensures that lighting remains correctly distributed on the stretched surface; without it, the lighting would appear severely distorted and unrealistic.
Code Examples
1
2// Calculate the normal in world space.
3// This is the first step for almost any lighting effect.
4const normalWorld = modelNormalMatrix.mul( normal() ).normalize();
5