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

gerstnerWave: Physically-Based Ocean Wave Generator

Mathematical Foundation of Water Surface Dynamics

The Gerstner wave represents the most physically accurate mathematical model for ocean surface simulation. Unlike simple sine wave approximations, Gerstner waves reproduce the characteristic sharp crests and rounded troughs observed in real ocean conditions.

The mathematical foundation centers on the wave equation where particle motion follows elliptical trajectories rather than simple vertical oscillations. The core formula relates wave steepness AA to wavelength λ\lambda through the wave number k=2πλk = \frac{2\pi}{\lambda}:

P(x,t)=P0+Aksin(k(d^P0ct))d^+Acos(k(d^P0ct))n^\vec{P}(x,t) = \vec{P}_0 + \frac{A}{k}\sin(k(\hat{d} \cdot \vec{P}_0 - ct)) \hat{d} + A\cos(k(\hat{d} \cdot \vec{P}_0 - ct)) \hat{n}

Where c=gkc = \sqrt{\frac{g}{k}} represents the phase velocity derived from deep water gravity wave theory, d^\hat{d} denotes the normalized wave direction vector, and n^\hat{n} represents the surface normal.

ライブエディター
const fragment = () => {
      const waves = gerstnerWave(uv.mul(4), vec2(1, 0.3), 0.8, 2, iTime.mul(0.5))
      const height = waves.y.add(0.5)
      const foam = vec3(0.1, 0.4, 0.7).select(vec3(1), height.greaterThan(0.9))
      return vec4(foam.mul(height), 1)
}