メインコンテンツまでスキップ

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:

hammersley(i,N)=(iN,Φ2(i))\text{hammersley}(i, N) = \left(\frac{i}{N}, \Phi_2(i)\right)

Where Φ2(i)\Phi_2(i) is the radical inverse function in base 2:

Φ2(i)=k=0bk(i)2(k+1)\Phi_2(i) = \sum_{k=0}^{\infty} b_k(i) \cdot 2^{-(k+1)}

Hemisphere Cosine Sampling:

ϕ=2πu1cosθ=1u2sinθ=u2\begin{align} \phi &= 2\pi u_1 \\ \cos\theta &= \sqrt{1 - u_2} \\ \sin\theta &= \sqrt{u_2} \end{align}

Resulting in 3D coordinates: (cosϕsinθ,sinϕsinθ,cosθ)(\cos\phi \sin\theta, \sin\phi \sin\theta, \cos\theta)

Properties:

  • (u1,u2)(u_1, u_2): Hammersley sequence coordinates [0,1]2\in [0,1]^2
  • NN: 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)

}