You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -103,16 +118,42 @@ See [Development Workflow](doc/workflow.md) for the full step-by-step guide.
103
118
104
119
---
105
120
121
+
## WebGPU Compute — Development Guide
122
+
123
+
The library supports a **dual-path architecture**: WebGL (CPU simulation + GLSL) and WebGPU (GPU compute simulation + TSL materials). See [Architecture](doc/architecture.md) for the full technical deep-dive.
124
+
125
+
### Key Design Decisions
126
+
127
+
-**Additive, non-breaking:** All WebGPU code is in `webgpu/` and the separate `src/webgpu.ts` entry point. The WebGL path is never modified.
128
+
-**Opt-in registration:** Users call `registerTSLMaterialFactory()` to enable WebGPU. If not called, only GLSL shaders are used.
129
+
-**Duck-typed detection:**`isComputeCapableRenderer()` checks for `.compute()` and `.hasFeature()` methods — no hard dependency on `THREE.WebGPURenderer`.
130
+
-**Single compute dispatch:** All modifiers run in one GPU compute pass (compile-time branching via TSL, not runtime branching).
131
+
-**Collision planes on GPU:** Collision planes use the same dual-path pattern as force fields — CPU logic in `three-particles-collision.ts`, GPU compute in `webgpu/compute-collision-planes.ts`. Plane data is encoded into a packed Float32Array and uploaded as a uniform buffer.
132
+
-**Curve baking:** Lifetime curves are pre-baked to 256-sample Float32Arrays at system creation, stored in the `curveData` buffer.
133
+
-**Sub-emitters forced to CPU:** Sub-emitters always use `SimulationBackend.CPU` because they need CPU-side death detection callbacks.
134
+
-**Trail always CPU:**`RendererType.TRAIL` uses CPU simulation regardless of backend setting.
135
+
136
+
### When Working on WebGPU Code
137
+
138
+
-**TSL materials** (`webgpu/tsl-*.ts`): Each renderer type has its own TSL material. They detect GPU compute via the `gpuCompute` flag — when true, data comes from packed vec4 storage buffers; when false, from individual float attributes.
139
+
-**Compute shaders** (`webgpu/compute-*.ts`): Written in TSL (compiles to WGSL). Core physics, all 7 modifiers, and force fields run in a single dispatch.
140
+
-**Storage buffers:** 8 vec4 bindings per system. Layout documented in [Architecture](doc/architecture.md#storage-buffer-layout).
141
+
-**Testing:** WebGPU-specific tests are in `src/__tests__/three-particles-webgpu-integration.test.ts`. Use mock factories (no real WebGPU context in Jest).
142
+
-**Imports:**`three/tsl` and `three/webgpu` are external — never imported from the main entry point. They're only used inside `webgpu/` files.
143
+
144
+
---
145
+
106
146
## Detailed Documentation
107
147
108
148
Detailed guides are in `.claude/doc/` — read these on-demand, not loaded into every conversation:
109
149
110
150
| Document | When to read |
111
151
|----------|-------------|
112
-
|[Architecture](doc/architecture.md)| Understanding internal data flow, shader pipeline, module responsibilities|
|[WebGPU Compute Plan](doc/webgpu-compute-plan.md)| Original implementation plan (all 6 phases completed) — useful as historical reference for design decisions |
116
157
117
158
---
118
159
@@ -125,6 +166,7 @@ Detailed guides are in `.claude/doc/` — read these on-demand, not loaded into
0 commit comments