Ocean Sim is a real-time physically inspired ocean surface simulation built using Three.js and spectral wave modeling.
Unlike simple texture-based oceans, this project generates waves using real-world fluid dynamics principles, evolving the ocean surface over time in the frequency domain using Fourier analysis.
The result is an ocean renderer with:
- Dynamic wave motion
- Physically correct dispersion behavior
- HDR sky reflections
- Professional PBR shading + animated ripples
✅ Real-time deep-water wave simulation using Fourier spectrum
✅ Time-evolving wave motion based on dispersion physics
✅ Inverse FFT height reconstruction
✅ Dynamic vertex displacement mesh rendering
✅ Physical-based shading (PBR Water)
✅ HDR environment reflections and sun glints
✅ Dual animated normal maps for micro ripples
✅ Infinite ocean tiling illusion
✅ Orbit camera controls with realism limits
✅ Looping ocean ambience sound + mute/play UI
Clone the repository:
git clone https://github.com/yourusername/ocean-sim.git
cd ocean-simInstall dependencies:
npm installRun the development server:
npm run devBuild for production:
npm run buildStart the simulation:
npm run devOpen your browser at:
http://localhost:5173
Controls:
- Left Mouse → Rotate camera
- Scroll Wheel → Zoom in/out (limited)
- Sound Button → Toggle ocean ambience
Ocean Sim is based on spectral ocean simulation, a technique used in:
- AAA games
- Film VFX oceans
- Scientific wave modeling
Instead of manually animating vertices, the ocean surface is generated through wave energy distribution in the frequency domain.
The surface height is modeled as a sum of sinusoidal waves:
Where:
-
$h(x,t)$ = height at position$x$ and time$t$ -
$k$ = wave vector (frequency + direction) -
$H(k,t)$ = spectral wave amplitude -
$e^{i(k\cdot x)}$ = Fourier basis function
The simulation begins with an initial random spectrum:
-
$\xi_r,\xi_i$ = Gaussian random noise -
$P(k)$ = wave energy spectrum
Ocean energy depends on wind direction and wavelength:
-
$A$ = amplitude constant -
$w$ = wind direction vector $L = \frac{V^2}{g}$ -
$g$ = gravity -
$V$ = wind speed
This ensures large waves dominate naturally.
Waves evolve over time via dispersion physics:
Wave angular frequency follows:
Meaning:
- Small waves travel faster
- Large swells move slower
After evolving
This gives per-vertex displacement values for rendering.
Ocean Sim follows a professional real-time rendering pipeline:
File: initialWave.ts
Generates
File: timeEvolution.ts
Applies dispersion equation:
Ht = H0 * exp(i * omega * t);File: map.ts
Performs inverse FFT:
heightMap = IFFT(Ht);File: updateOceanMesh.ts
Updates geometry vertices:
positions[i + 1] = height * scale;
geometry.computeVertexNormals();Uses MeshPhysicalMaterial:
const material = new THREE.MeshPhysicalMaterial({
roughness: 0.02,
clearcoat: 1.0,
envMapIntensity: 2.2,
});new RGBELoader().load("/hdri/4k.hdr", (texture) => {
scene.environment = envMap;
});Provides:
- Sky reflections
- Sun glints
- Realistic brightness response
Two normal maps animated in opposite directions:
normalMap.offset.x += 0.0003;
clearcoatNormalMap.offset.x -= 0.00015;The mesh follows the camera:
ocean.position.x = camera.position.x;
ocean.position.z = camera.position.z;Creates endless ocean without huge geometry.
Ocean shading approximates the Rendering Equation:
Where:
-
$f_r$ = BRDF reflectance function -
$L_i$ = incoming light -
$L_o$ = outgoing reflected radiance
This governs realistic reflections and water highlights.
- Fourier Transform Surface Reconstruction (IFFT)
- Phillips Wave Spectrum
- Dispersion Physics Evolution
- Physically Based Rendering (PBR)
- Infinite Surface Tiling
- Animated Normal Flow
- TypeScript
- Three.js
- WebGL
- HDR Environment Lighting
- Spectral Wave Physics
- FFT-Based Ocean Simulation
Ocean Output Placeholder:
Planned improvements:
- GPU FFT via Compute Shaders
- Foam & crest detection
- Beaufort wind control scaling
- Underwater scattering model
- Ship wake interactions
This project is licensed under the MIT License. See the LICENSE file for details.
Built by Sudhanshu Mani A physically inspired ocean simulation combining:
- Mathematics
- Fluid wave physics
- Modern real-time graphics