reflect
Calculates the reflection direction of an incident vector relative to a surface normal based on the physical law of reflection, used to create mirror-like effects.
Core Advantages
Provides a physically accurate and high-performance GPU built-in function, serving as a fundamental building block for implementing various reflective effects like environment mapping and planar reflections.
Common Uses
Environment Mapping to simulate skybox reflections
Planar Reflections to create mirrors or water surfaces
Procedural effects (like MatCap effects)
How to adjust
Adjust the effect by changing the normal vector `N` input. For example, replacing `N` with a normal read from a normal map adds bumpy details to the reflection. Adding a noise vector to `N` creates a frosted or blurry reflection effect.
Code Examples
1// Calculate incident vector I (from camera to surface)
2const I = positionWorld.sub(cameraPosition).normalize();
3
4// Get surface normal N
5const N = normalWorld.normalize();
6
7// Calculate reflection vector R
8const reflectVec = reflect(I, N);
9
10// Use reflection vector R to sample the environment map
11const reflectionColor = envMap.uv(reflectVec);