transformNormal
Correctly transforms a normal vector from local space to another coordinate space (defaults to world space), specifically solving incorrect lighting issues that arise when a model has non-uniform scaling.
Core Advantages
Guarantees correct lighting calculations even with non-uniform scaling, while optimizing performance with a more efficient mathematical approach and greatly simplifying development by encapsulating complex logic.
Common Uses
Standard PBR or Blinn-Phong lighting
Triplanar Mapping
Procedural terrain or water shading
How to adjust
Adjust in two main ways: First, always use `.normalize()` on the result, otherwise, model scaling will cause incorrect lighting intensity. Second, you can replace the input normal, e.g., using a noise function to create a bumpy surface effect. Third, you can explicitly provide a second argument (like `modelViewMatrix`) to transform the normal into a different coordinate space (like view space) for calculations.
Code Examples
1// Transform the local normal to world space.
2// The node automatically uses modelWorldMatrix for transformation.
3// Note: Its output is not guaranteed to be a unit vector and usually requires manual normalization.
4const worldNormal = transformNormal( normalLocal ).normalize();