Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.5 — Compute Shaders for Particles
3D Web · Example 2 of 2

Compute before init, read-back and workgroup limits

WebGPU prints the real limits and, for a 512-size workgroup, a long error from the browser (the text depends on the GPU). The fallback prints no WebGPU device and a getScopedArray error. No output.

A compute shader is a GPU program that draws nothing: it reads and writes buffers. With instancedArray and compute() the GPU moves 20,000 particles each frame while JavaScript only presses start. On the WebGL 2 fallback it still runs, with limits.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 3 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add a floor bounce to the update kernel: when a particle hits y < 0, flip and halve its vertical velocity instead of respawning.

02

Write one line that reads the first particle's position back to JavaScript for a test.

Explain it without notes

01

Why is a compute shader better than a JavaScript loop for 20,000 particles?

02

What happens to compute when the renderer falls back to WebGL 2?

Compute before init, read-back and workgroup limits
Press Run to see the page.
idle

Console

Nothing logged yet.