# jeantimex/webgpu-water architecture

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

- Interactive diagram: https://gitdiagram.com/jeantimex/webgpu-water
- Repository: https://github.com/jeantimex/webgpu-water

## Overview

This is an interactive browser-based WebGPU water demo. Users orbit the camera, move a buoyant sphere, and draw ripples; the app updates the GPU heightfield, derives normals and caustics, then renders the pool, sphere, and reflective/refractive water against a cubemap. The graph preserves the README’s simulation and rendering stages. Source excerpts show the main component wiring and several resource relationships; shader-pass sequencing is documented in the README, while unsampled implementation details are not inferred.

Main entry points: [`src/main.ts`](https://github.com/jeantimex/webgpu-water/blob/main/src/main.ts) (App loop and controls), [`src/water.ts`](https://github.com/jeantimex/webgpu-water/blob/main/src/water.ts) (Water simulation and rendering), [`src/pool.ts`](https://github.com/jeantimex/webgpu-water/blob/main/src/pool.ts) (Pool renderer), [`src/sphere.ts`](https://github.com/jeantimex/webgpu-water/blob/main/src/sphere.ts) (Sphere renderer and geometry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["App loop and controls<br/>[main.ts]"]
  node_ray["Ray casting and math<br/>[lightgl.ts]"]
  node_types["Shared types<br/>[types.ts]"]
end

subgraph group_simulation["Water Simulation"]
  node_water["Water simulation and rendering<br/>[water.ts]"]
end

subgraph group_scene["Scene Rendering"]
  node_pool["Pool renderer<br/>[pool.ts]"]
  node_sphere["Sphere renderer and geometry<br/>[sphere.ts]"]
  node_cubemap["Cubemap loader<br/>[cubemap.ts]"]
end

subgraph group_shaders["WGSL Shaders"]
  node_sim_shaders["Wave and normal passes"]
  node_caustics_shaders["Caustics passes"]
  node_surface_shaders["Water surface passes"]
  node_pool_shaders["Pool shaders"]
  node_sphere_shaders["Sphere shaders"]
end

node_user(("Demo user"))
node_browser_gpu["Browser WebGPU"]

node_user -->|"interacts with"| node_main
node_main -->|"initializes"| node_browser_gpu
node_main -->|"casts interaction rays"| node_ray
node_main -->|"loads skybox"| node_cubemap
node_main -->|"creates and renders"| node_pool
node_main -->|"creates and updates"| node_sphere
node_main -->|"creates and advances"| node_water
node_main -->|"adds ripple drops"| node_water
node_cubemap -->|"uploads cubemap texture"| node_browser_gpu
node_water -->|"runs simulation passes"| node_sim_shaders
node_water -->|"generates caustics"| node_caustics_shaders
node_water -->|"renders water surface"| node_surface_shaders
node_pool -->|"uses shaders"| node_pool_shaders
node_sphere -->|"uses shaders"| node_sphere_shaders
node_main -->|"uses shared definitions"| node_types

click node_main "https://github.com/jeantimex/webgpu-water/blob/main/src/main.ts"
click node_ray "https://github.com/jeantimex/webgpu-water/blob/main/src/lightgl.ts"
click node_types "https://github.com/jeantimex/webgpu-water/blob/main/src/types.ts"
click node_water "https://github.com/jeantimex/webgpu-water/blob/main/src/water.ts"
click node_pool "https://github.com/jeantimex/webgpu-water/blob/main/src/pool.ts"
click node_sphere "https://github.com/jeantimex/webgpu-water/blob/main/src/sphere.ts"
click node_cubemap "https://github.com/jeantimex/webgpu-water/blob/main/src/cubemap.ts"
click node_sim_shaders "https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water"
click node_caustics_shaders "https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water"
click node_surface_shaders "https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water"
click node_pool_shaders "https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/pool"
click node_sphere_shaders "https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/sphere"

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_main,node_ray,node_types,node_user,node_browser_gpu toneBlue
class node_water toneAmber
class node_pool,node_sphere,node_cubemap toneMint
class node_sim_shaders,node_caustics_shaders,node_surface_shaders,node_pool_shaders,node_sphere_shaders toneRose
```

## Components

### Application

- [App loop and controls](https://github.com/jeantimex/webgpu-water/blob/main/src/main.ts): `src/main.ts`
- [Ray casting and math](https://github.com/jeantimex/webgpu-water/blob/main/src/lightgl.ts): `src/lightgl.ts`
- [Shared types](https://github.com/jeantimex/webgpu-water/blob/main/src/types.ts): `src/types.ts`

### Water Simulation

- [Water simulation and rendering](https://github.com/jeantimex/webgpu-water/blob/main/src/water.ts): `src/water.ts`

### Scene Rendering

- [Pool renderer](https://github.com/jeantimex/webgpu-water/blob/main/src/pool.ts): `src/pool.ts`
- [Sphere renderer and geometry](https://github.com/jeantimex/webgpu-water/blob/main/src/sphere.ts): `src/sphere.ts`
- [Cubemap loader](https://github.com/jeantimex/webgpu-water/blob/main/src/cubemap.ts): `src/cubemap.ts`

### WGSL Shaders

- [Wave and normal passes](https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water): `src/shaders/water`
- [Caustics passes](https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water): `src/shaders/water`
- [Water surface passes](https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/water): `src/shaders/water`
- [Pool shaders](https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/pool): `src/shaders/pool`
- [Sphere shaders](https://github.com/jeantimex/webgpu-water/tree/main/src/shaders/sphere): `src/shaders/sphere`

### Other components

- **Demo user**
- **Browser WebGPU**

## Connections

- Demo user → App loop and controls: interacts with (evidence: `src/main.ts`)
- App loop and controls → Browser WebGPU: initializes (evidence: `src/main.ts`)
- App loop and controls → Ray casting and math: casts interaction rays (evidence: `src/main.ts`)
- App loop and controls → Cubemap loader: loads skybox (evidence: `src/main.ts`)
- App loop and controls → Pool renderer: creates and renders (evidence: `src/main.ts`)
- App loop and controls → Sphere renderer and geometry: creates and updates (evidence: `src/main.ts`)
- App loop and controls → Water simulation and rendering: creates and advances (evidence: `src/main.ts`)
- App loop and controls → Water simulation and rendering: adds ripple drops (evidence: `src/main.ts`)
- Cubemap loader → Browser WebGPU: uploads cubemap texture (evidence: `src/cubemap.ts`)
- Water simulation and rendering → Wave and normal passes: runs simulation passes (evidence: `README.md`)
- Water simulation and rendering → Caustics passes: generates caustics (evidence: `README.md`)
- Water simulation and rendering → Water surface passes: renders water surface (evidence: `src/water.ts`)
- Pool renderer → Pool shaders: uses shaders (evidence: `src/pool.ts`)
- Sphere renderer and geometry → Sphere shaders: uses shaders (evidence: `src/sphere.ts`)
- App loop and controls → Shared types: uses shared definitions (evidence: `src/main.ts`)
