# levalo/ocean-rendering architecture

> Architecture diagram of the GitHub repository levalo/ocean-rendering, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/levalo/ocean-rendering
- Repository: https://github.com/levalo/ocean-rendering

## Overview

ocean-rendering is a browser-based WebGL ocean-and-sky renderer. Its frame loop updates sky state, renders an environment map, computes ocean frequency data and transforms it with an FFT, then draws visible ocean patches using the resulting height texture and sky reflection. The graph preserves the documented runtime stages and rendering components; several connections come from the frame-loop excerpt or the SOURCE INDEX, so unsampled internals are not inferred beyond those references.

Main entry points: [`src/index.ts`](https://github.com/levalo/ocean-rendering/blob/main/src/index.ts) (Render loop), [`src/world/Ocean.ts`](https://github.com/levalo/ocean-rendering/blob/main/src/world/Ocean.ts) (Ocean model), [`src/graphic/Camera.ts`](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/Camera.ts) (Camera), [`src/common/QuadTree.ts`](https://github.com/levalo/ocean-rendering/blob/main/src/common/QuadTree.ts) (Ocean LOD)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_application["WebGL application<br/>[Application.ts]"]
  node_frame["Render loop<br/>[index.ts]"]
  node_camera["Camera<br/>[Camera.ts]"]
end

subgraph group_world["World models"]
  node_ocean["Ocean model<br/>[Ocean.ts]"]
  node_sky["Sky model<br/>[Sky.ts]"]
  node_quadtree["Ocean LOD<br/>[QuadTree.ts]"]
  node_geometry["World geometry<br/>[Geometry.ts]"]
end

subgraph group_simulation["Wave simulation"]
  node_frequency["Frequency simulator"]
  node_envmap["Environment simulator<br/>[EnvMapSimulator.ts]"]
  node_fft["FFT transform<br/>[FFT.ts]"]
  node_math["Math helpers<br/>[math.ts]"]
end

subgraph group_rendering["Rendering"]
  node_drawsky["Sky simulation command<br/>[SimulateSky.ts]"]
  node_drawskybox["Skybox renderer<br/>[DrawSkybox.ts]"]
  node_drawocean["Ocean renderer<br/>[DrawOcean.ts]"]
  node_fftstage["FFT stage command<br/>[RunFFTStage.ts]"]
  node_freqcommand["Frequency command"]
  node_plane["Plane mesh<br/>[Plane.ts]"]
  node_cube["Cube mesh<br/>[Cube.ts]"]
  node_axes["Axes renderer<br/>[DrawAxes.ts]"]
  node_picture["Picture renderer<br/>[DrawPicture.ts]"]
end

node_browser(("Browser input"))

node_browser -->|"controls view"| node_camera
node_application -->|"creates"| node_camera
node_frame -->|"uses WebGL"| node_application
node_frame -->|"updates"| node_sky
node_frame -->|"reads ocean state"| node_ocean
node_frame -->|"runs"| node_envmap
node_frame -->|"draws skybox"| node_drawskybox
node_frame -->|"runs"| node_frequency
node_frame -->|"runs"| node_fft
node_frame -->|"draws visible patches"| node_drawocean
node_ocean -->|"creates and reads"| node_quadtree
node_ocean -->|"creates and updates"| node_geometry
node_ocean -->|"subscribes to changes"| node_camera
node_quadtree -->|"creates GPU buffers"| node_application
node_quadtree -->|"uses LOD helper"| node_math
node_camera -->|"uses angle conversion"| node_math
node_frame -->|"constructs simulator"| node_freqcommand
node_frequency -.->|"dispatches simulation"| node_freqcommand
node_frame -->|"FFT dispatches stages"| node_fftstage
node_frame -->|"configures sky simulation"| node_drawsky
node_envmap -->|"uses simulation command"| node_drawsky
node_drawsky -->|"uses mesh"| node_cube
node_drawskybox -->|"uses mesh"| node_cube
node_drawskybox -->|"uses mesh"| node_plane
node_freqcommand -->|"uses mesh"| node_plane
node_fftstage -->|"uses mesh"| node_plane
node_frame -.->|"optional debug draw"| node_axes
node_frame -.->|"optional debug draw"| node_picture

click node_application "https://github.com/levalo/ocean-rendering/blob/main/src/Application.ts"
click node_frame "https://github.com/levalo/ocean-rendering/blob/main/src/index.ts"
click node_camera "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/Camera.ts"
click node_ocean "https://github.com/levalo/ocean-rendering/blob/main/src/world/Ocean.ts"
click node_sky "https://github.com/levalo/ocean-rendering/blob/main/src/world/Sky.ts"
click node_quadtree "https://github.com/levalo/ocean-rendering/blob/main/src/common/QuadTree.ts"
click node_geometry "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/Geometry.ts"
click node_frequency "https://github.com/levalo/ocean-rendering/blob/main/src/common/FrequencySimulator.ts"
click node_envmap "https://github.com/levalo/ocean-rendering/blob/main/src/common/EnvMapSimulator.ts"
click node_fft "https://github.com/levalo/ocean-rendering/blob/main/src/common/FFT.ts"
click node_math "https://github.com/levalo/ocean-rendering/blob/main/src/helpers/math.ts"
click node_drawsky "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/SimulateSky.ts"
click node_drawskybox "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawSkybox.ts"
click node_drawocean "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawOcean.ts"
click node_fftstage "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/RunFFTStage.ts"
click node_freqcommand "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/SimulateFrequency.ts"
click node_plane "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/resources/Plane.ts"
click node_cube "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/resources/Cube.ts"
click node_axes "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawAxes.ts"
click node_picture "https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawPicture.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_application,node_frame,node_camera,node_browser toneBlue
class node_ocean,node_sky,node_quadtree,node_geometry toneAmber
class node_frequency,node_envmap,node_fft,node_math toneMint
class node_drawsky,node_drawskybox,node_drawocean,node_fftstage,node_freqcommand,node_plane,node_cube,node_axes,node_picture toneRose
```

## Components

### Runtime

- [WebGL application](https://github.com/levalo/ocean-rendering/blob/main/src/Application.ts): `src/Application.ts`
- [Render loop](https://github.com/levalo/ocean-rendering/blob/main/src/index.ts): `src/index.ts`
- [Camera](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/Camera.ts): `src/graphic/Camera.ts`

### World models

- [Ocean model](https://github.com/levalo/ocean-rendering/blob/main/src/world/Ocean.ts): `src/world/Ocean.ts`
- [Sky model](https://github.com/levalo/ocean-rendering/blob/main/src/world/Sky.ts): `src/world/Sky.ts`
- [Ocean LOD](https://github.com/levalo/ocean-rendering/blob/main/src/common/QuadTree.ts): `src/common/QuadTree.ts`
- [World geometry](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/Geometry.ts): `src/graphic/Geometry.ts`

### Wave simulation

- [Frequency simulator](https://github.com/levalo/ocean-rendering/blob/main/src/common/FrequencySimulator.ts): `src/common/FrequencySimulator.ts`
- [Environment simulator](https://github.com/levalo/ocean-rendering/blob/main/src/common/EnvMapSimulator.ts): `src/common/EnvMapSimulator.ts`
- [FFT transform](https://github.com/levalo/ocean-rendering/blob/main/src/common/FFT.ts): `src/common/FFT.ts`
- [Math helpers](https://github.com/levalo/ocean-rendering/blob/main/src/helpers/math.ts): `src/helpers/math.ts`

### Rendering

- [Sky simulation command](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/SimulateSky.ts): `src/graphic/commands/SimulateSky.ts`
- [Skybox renderer](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawSkybox.ts): `src/graphic/commands/DrawSkybox.ts`
- [Ocean renderer](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawOcean.ts): `src/graphic/commands/DrawOcean.ts`
- [FFT stage command](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/RunFFTStage.ts): `src/graphic/commands/RunFFTStage.ts`
- [Frequency command](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/SimulateFrequency.ts): `src/graphic/commands/SimulateFrequency.ts`
- [Plane mesh](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/resources/Plane.ts): `src/graphic/resources/Plane.ts`
- [Cube mesh](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/resources/Cube.ts): `src/graphic/resources/Cube.ts`
- [Axes renderer](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawAxes.ts): `src/graphic/commands/DrawAxes.ts`
- [Picture renderer](https://github.com/levalo/ocean-rendering/blob/main/src/graphic/commands/DrawPicture.ts): `src/graphic/commands/DrawPicture.ts`

### Other components

- **Browser input**

## Connections

- Browser input → Camera: controls view (evidence: `src/graphic/Camera.ts`)
- WebGL application → Camera: creates (evidence: `src/Application.ts`)
- Render loop → WebGL application: uses WebGL (evidence: `src/index.ts`)
- Render loop → Sky model: updates (evidence: `src/index.ts`)
- Render loop → Ocean model: reads ocean state (evidence: `src/index.ts`)
- Render loop → Environment simulator: runs (evidence: `src/index.ts`)
- Render loop → Skybox renderer: draws skybox (evidence: `src/index.ts`)
- Render loop → Frequency simulator: runs (evidence: `src/index.ts`)
- Render loop → FFT transform: runs (evidence: `src/index.ts`)
- Render loop → Ocean renderer: draws visible patches (evidence: `src/index.ts`)
- Ocean model → Ocean LOD: creates and reads (evidence: `src/world/Ocean.ts`)
- Ocean model → World geometry: creates and updates (evidence: `src/world/Ocean.ts`)
- Ocean model → Camera: subscribes to changes (evidence: `src/world/Ocean.ts`)
- Ocean LOD → WebGL application: creates GPU buffers (evidence: `src/common/QuadTree.ts`)
- Ocean LOD → Math helpers: uses LOD helper (evidence: `src/common/QuadTree.ts`)
- Camera → Math helpers: uses angle conversion (evidence: `src/graphic/Camera.ts`)
- Render loop → Frequency command: constructs simulator (evidence: `src/index.ts`)
- Frequency simulator → Frequency command: dispatches simulation (evidence: `src/common/FrequencySimulator.ts`)
- Render loop → FFT stage command: FFT dispatches stages
- Render loop → Sky simulation command: configures sky simulation (evidence: `src/index.ts`)
- Environment simulator → Sky simulation command: uses simulation command (evidence: `src/common/EnvMapSimulator.ts`)
- Sky simulation command → Cube mesh: uses mesh (evidence: `src/graphic/commands/SimulateSky.ts`)
- Skybox renderer → Cube mesh: uses mesh (evidence: `src/graphic/commands/DrawSkybox.ts`)
- Skybox renderer → Plane mesh: uses mesh (evidence: `src/graphic/commands/DrawSkybox.ts`)
- Frequency command → Plane mesh: uses mesh (evidence: `src/graphic/commands/SimulateFrequency.ts`)
- FFT stage command → Plane mesh: uses mesh (evidence: `src/graphic/commands/RunFFTStage.ts`)
- Render loop → Axes renderer: optional debug draw (evidence: `src/index.ts`)
- Render loop → Picture renderer: optional debug draw (evidence: `src/index.ts`)
