Module 06 / WEBGPU
WebGPU compute
A million particles
WebGPU lets a page compute on the graphics card, not just draw: millions of independent calculations, every frame.
Why it matters
- What you're looking at
- The FM01 as up to two million particles. Each frame a compute shader springs every one home, pushes it from your pointer and drifts it; switch the physics to the CPU to compare.
- Why it matters
- Simulation, particles, image processing and AI inference at native-app scale in a browser: a million particles at 60 fps here, where the same JavaScript on a fast Mac manages about half.
- The trade-off
- The newest API: Chrome, Edge and Safari 26 and later, Firefox catching up. WebGL 2 runs the same rules on fewer particles. Shaders and GPU bugs are harder to work with.
Loading stage…
Module notes
The FM01 Pocket Communicator as a million particles the GPU moves every frame. Drag through it and it scatters like sand, then pulls itself back together; take it apart by hand; then run the same physics on the CPU and feel the difference.
- This browser
- checking…
- Native path
- three.js TSL on WebGPU · compute shaders needs WebGPU
- Fallback
- Fewer particles on WebGL 2 needs WebGL 2
- Status
- Live since 2026-10-11
- Payload
- The FM01 (fm01.glb, sampled into particles) · 1.4 MB
- three.js WebGPU renderer and core · 272 KB
- GLTFLoader · 13 KB
- TSL (the shading language) · 7 KB
- Stage code · 9 KB
- Budget
- Payload 1.7 MB · budget ≤ 2 MB Within
- First frame desktop 2.6 s · phone 1.1 s · budget ≤ 3.0 s Within
- Frame rate desktop 60 fps · phone 60 fps · budget ≥ 55 fps desktop · ≥ 30 phone Within
- Browser support
-
First version with each feature · caniuse, 2026-10-11Feature Chrome Safari Firefox WebGPU: rendering and compute shaders (Safari on macOS 26; Firefox on Windows, and Apple-silicon Macs from 145) 113 26 141 WebGPU on phones (Android, iOS) 121 26 Not yet WebGL 2 (the fallback: transform feedback) 56 15 51 - Tags
Module 06 / Use it on your page
three.js's WebGPURenderer with TSL: write compute and shading once in JavaScript. It compiles to WGSL on WebGPU and to GLSL on WebGL 2.
npm three 0.183 (renderer, TSL and GLTFLoader about 290 KB) · the FM01 GLB (1.4 MB), sampled into particles
-
Step 1
Start the renderer
One renderer for both GPU APIs: it takes WebGPU where the browser has it and WebGL 2 where it doesn't.
import * as THREE from "three/webgpu"; const renderer = new THREE.WebGPURenderer({ canvas, antialias: true }); await renderer.init(); console.log(renderer.backend.isWebGPUBackend ? "WebGPU" : "WebGL 2"); -
Step 2
Write the compute kernel in TSL
Storage buffers hold every particle's position and velocity; the kernel runs once per particle, on the GPU.
import { Fn, instancedArray, instanceIndex, uniform, vec4 } from "three/tsl"; const P = instancedArray(count, "vec4"); // positions const V = instancedArray(count, "vec4"); // velocities const dt = uniform(0); const update = Fn(() => { const p = P.element(instanceIndex).xyz; const v = V.element(instanceIndex).xyz; P.element(instanceIndex).assign(vec4(p.add(v.mul(dt)), 1)); })().compute(count); -
Step 3
Draw from the same buffer
A sprite material reads the positions straight from GPU memory: nothing comes back to JavaScript.
const material = new THREE.SpriteNodeMaterial(); material.positionNode = P.toAttribute().xyz; const particles = new THREE.Sprite(material); particles.count = count; scene.add(particles); -
Step 4
Run both each frame
Compute, then render.
renderer.setAnimationLoop(() => { dt.value = clock.getDelta(); renderer.compute(update); renderer.render(scene, camera); });
Serving it
- WebGPU needs https (or localhost): over plain http on a LAN, navigator.gpu isn't there.
- Use vec4 for buffers the CPU writes. three re-pads vec3 storage on upload and scrambles it on WebGPU.
- three doesn't recover a lost GPU on its own: set renderer.onDeviceLost and rebuild on a fresh canvas.
- Serve the GLB gzipped: about half the size.