Low-Discrepancy Sampling for Monte Carlo Rendering
Mathematical Foundation: Low-Discrepancy Sequence Generation
The Hammersley sequence provides mathematically optimal point distributions that minimize discrepancy compared to truly random sampling, enabling superior Monte Carlo integration convergence.
Mathematical Definition:
Where is the radical inverse function in base 2:
Hemisphere Cosine Sampling:
Resulting in 3D coordinates:
Properties:
- : Hammersley sequence coordinates
- : Total number of samples
- Low-discrepancy property ensures even distribution
- Cosine weighting matches Lambert's law for realistic lighting
Surface Lighting Simulation
ライブエディター
const fragment = () => { const gridSize = 16.0 const cellPos = uv.mul(gridSize) const cellIndex = cellPos.x.floor().add(cellPos.y.floor().mul(gridSize)) const sampleCount = int(256) const hammersleySample = hammersley(cellIndex.floor().toInt(), sampleCount) const lightDirection = hemisphereCosSample(hammersleySample) const surfaceNormal = vec3(0, 0, 1) const lambertian = lightDirection.dot(surfaceNormal).max(0) const fresnel = float(1).sub(lambertian).pow(5).mul(0.04).add(0.96) const finalColor = vec3(lambertian).mul(fresnel) const brightness = iTime.add(cellIndex.mul(0.1)).sin().mul(0.2).add(0.8) return vec4(finalColor.mul(brightness), 1) }