parallaxMapping: Multi-Algorithm Surface Displacement
Adaptive Heightmap Processing with Four Implementation Variants
The parallaxMapping collection provides four distinct algorithms for heightmap-based surface displacement. Each variant offers different quality-performance characteristics suitable for various rendering scenarios.
Mathematical Foundation
Given a viewing vector and texture coordinate , parallax mapping adjusts surface coordinates based on heightmap data . The displacement follows:
where represents the scale factor and the displacement direction.
Algorithm Variants
Function | Quality | Performance | Description |
---|---|---|---|
parallaxMappingSimple | Low | High | Single-sample approximation |
parallaxMappingSteep | Medium | Medium | Layer-based stepping |
parallaxMappingRelief | High | Low | Binary refinement |
parallaxMappingOcclusion | Highest | Lowest | Interpolated occlusion |
Algorithm Details
Simple Parallax
Direct offset calculation without iteration:
Steep Parallax
Layer-based stepping with adaptive resolution:
- Layer count:
- Step size:
Relief Mapping
Binary refinement after initial stepping for sub-pixel accuracy.
Occlusion Mapping
Linear interpolation between intersection points:
Live Editor
const fragment = () => { const heightTex = uniform('https://avatars.githubusercontent.com/u/40712342') const viewDir = vec3(uv.sub(0.5).mul(2), 1).normalize() const displaced = parallaxMappingSimple(heightTex, viewDir, uv) return texture(heightTex, displaced) }