Skip to content

Acerola-style FFT ocean simulation (GL 4.3 compute)#1

Open
SurajBhari wants to merge 2 commits into
bigloosegoose:mainfrom
SurajBhari:feature/fft-ocean
Open

Acerola-style FFT ocean simulation (GL 4.3 compute)#1
SurajBhari wants to merge 2 commits into
bigloosegoose:mainfrom
SurajBhari:feature/fft-ocean

Conversation

@SurajBhari

Copy link
Copy Markdown

What

Adds a real-time, FFT-based ocean (Tessendorf / Acerola style) to the engine, driven by GPU compute shaders. Design spec: docs/superpowers/specs/2026-06-23-fft-ocean-design.md.

Press O at runtime to toggle between the ocean (default) and the previous cube/grass scene.

How it works

Engine

  • GL context bumped 3.3 → 4.3 (GLAD already exported the compute entry points — no regeneration needed).
  • New header-only ComputeShader class; Shader gains setVec2/setVec4. No .vcxproj changes (everything is header-only + runtime-loaded shaders, matching existing conventions).

Simulation (per cascade, N=256, 3 cascades @ L≈256/64/16 m)shaders/ocean/*.comp

  1. spectrum_init — Phillips spectrum × Gaussian → H0 (once).
  2. spectrum_update — evolve H0 by dispersion → packed frequency fields.
  3. butterfly_precompute — twiddles + bit-reversal (once).
  4. ifft — generic 2D inverse FFT, 8 horizontal + 8 vertical ping-pong stages (two complex fields per RGBA texture).
  5. ocean_merge — sign-correct/normalize → displacement map; normals + Jacobian foam via finite differences.

Render

  • Ocean class: owns textures/passes + a subdivided grid; ocean.vert displaces verts by summed cascades, ocean.frag does Fresnel(sky reflection ↔ deep water) + sun specular + foam + a cheap subsurface tint.
  • Sky class: analytic Preetham model, reused inside ocean.frag for reflections.

Deviations / notes

  • Sky: Hosek-Wilkie was requested, but its large published radiance dataset can't be reproduced faithfully by hand. Implemented Preetham (pre-approved fallback) — self-contained and visually close for a reflection sky.
  • Spectrum: used Phillips (Tessendorf classic) rather than JONSWAP — far less bug-prone to write without a runtime to verify against. Same Acerola look.
  • Also folds in the earlier grass texture-unit bugfix (same main.cpp).

⚠️ Verification — needs a build on your machine

No msbuild/Visual Studio was available in my environment, so I could not compile or run this. The architecture is complete and reviewed by hand, but expect to tune and shake out issues when you build it in VS:

  • Wave height is the most likely thing to need tuning — the 1/N² IFFT normalization makes it very sensitive to Ocean::amplitude (default 600) and dispScale. If the ocean looks flat, raise amplitude; if it explodes, lower it.
  • Watch the console for ERROR::COMPUTE_SHADER / ERROR::SHADER lines on startup.
  • Requires a GPU/driver supporting OpenGL 4.3.

- Upgrade GL context 3.3 -> 4.3; add ComputeShader class
- FFT ocean: JONSWAP/Phillips spectrum, GPU IFFT (butterfly ping-pong),
  3 cascades, displacement + normals + Jacobian foam (shaders/ocean/*)
- Ocean class orchestrates compute passes + displaced grid render
- Preetham analytic sky (Hosek-Wilkie fallback) reused for water reflections
- Water shading: Fresnel + sky reflection + sun specular + foam + SSS tint
- main.cpp integration with 'O' toggle vs existing scene
- Includes earlier grass texture-unit fix
@bigloosegoose bigloosegoose force-pushed the main branch 2 times, most recently from f6f42de to 7ece2f8 Compare July 12, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant