faceforward
Orients vector N using reference Nref and incident vector I: returns N if dot(Nref, I) < 0, otherwise −N. Used to keep normals consistently oriented on two‑sided or thin surfaces. Alias: faceForward (same as GLSL).
Core Advantages
Removes normal sign flips at constant cost, stabilizing diffuse, Fresnel/rim, and reflection/refraction across front/back transitions.
Common Uses
Consistent normals for two‑sided materials (avoid dark back faces or flipped highlights)
Stable Fresnel/rim masks and view‑dependent effects
Robust reflection/refraction on thin geometry
Reliable thresholding in procedural shading that depends on normal direction
How to adjust
No tunable parameters. Control behavior by choosing I and Nref: e.g., set I = lightDirection.negate() to orient toward the light, or switch to view‑space vectors (normalView, positionViewDirection) for space consistency. Ensure all three inputs are in the same space. Alias: faceForward. Exactly 3 parameters.
Code Examples
1// Consistent normal orientation (world space)
2const N = normalWorld.normalize();
3const I = viewDirection; // surface → camera
4const Nref = N; // use geometric normal as reference
5const N_oriented = faceforward( N, I, Nref );
6
7// Use oriented normal for stable diffuse
8const lambert = dot( N_oriented, lightDirection ).max( 0.0 );