Feature Library

Particle engine: a million on the GPU, lights included

4.79 GPU · 0.21 CPU ms
A still of the Particle engine: a million on the GPU, lights included demo
Still
The live demo starts when it’s in view.Pick a job; move the pointer over the fireflies or the swarm; drag to turn the view

A whole GPU particle runtime in raw WebGPU.

A whole GPU particle runtime in raw WebGPU: fixed pools per emitter, a stable live list built by prefix sums and drawn indirectly, so a million billboards simulate and draw in about 1.3 ms on a laptop GPU. Emitters are plain data: point, sphere, box, mesh (by area), path (by length) and field shapes; life curves for colour and size; gravity, drag, wind fields, curl noise, vortices and attractors; height-field collisions that bounce, stick or die; flocking and a small fluid; trails and ribbons; flipbooks; soft depth; smoke at half resolution; deposition into a grid; resting debris handed back to the app; and the brightest particles as tiled lights the app’s own surfaces read. One budget shared by every emitter, three quality tiers, replayable on the same device. No three.js, no dependencies.

What it costs a frame

4.79 ms
0.21 ms
GPU
4.79 ms
CPU, median
0.21 ms
CPU, 95th pct
0.38 ms
Draw calls
0
Weight
Heavy

Measured 25 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 4.22–4.99, CPU 0.21–0.42 ms). What ran: Alone: 1,000,000 small additive billboards in a box, births replacing deaths, simulated and drawn every frame (the engine’s own perf workload), then a tone pass to the canvas. No stage, lights or bloom. GPU time for the whole frame by timestamp queries. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.84 ms
1% low ?
55 fps
Varies by ?
±0.48 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.05 ms18.09 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.84 ms
p95 ?
17.70 ms
p99 ?
18.04 ms
Slowest ?
18.16 ms
Mean ?
16.86 ms
Standard deviation ?
0.48 ms
1% low ?
55 fps
0.1% low ?
55 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 0.8 / 1.2 ms

Input

No input during this run.

Memory

JavaScript heap ?
31.2 → 31.1 MB
Growth ?
-0.11 MB

Browser

JavaScript a frame ?
0.45 ms
All tasks a frame ?
0.99 ms
Layout / style ?
0.01 / 0.00 ms
Main thread busy ?
6%

Garbage collection

Collections ?
2 (2 minor, 0 major)
Pauses ?
3.2 ms in all, longest 2.2

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("particle-engine")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. Sparks, embers, dust, smoke and magic in a WebGPU game or world, all from one runtime and one budget
  2. Fireflies, torches and sparks that light the floor and walls round them without a light each
  3. Grinding, welding or impact sparks that bounce off the level and settle as debris the app takes over
  4. A swarm, a flock or a stream of particles that forms a logo, a word outline or a path, then breaks apart
  5. Smoke and steam from vents and chimneys, cheap enough at half resolution to have several
  6. Ash, snow or wetness that settles into a grid the app reads back as a layer on the ground
  7. A product or title moment with a million particles, where three.js particle systems run out

Pitfalls, in brief

  1. The demo needs WebGPU: the runtime is compute shaders, storage buffers and indirect draws, which WebGL 2 cannot do.
  2. Draw after your opaque pass and hand the runtime the opaque depth as a sampled texture (TEXTURE_BINDING), reverse-Z, with the depth pass ended.
  3. Depth must be reverse-Z (near 1, far 0) and the view camera-relative: positions are taken relative to the eye before the matrix. host.ts builds both; a three.js camera’s matrices are neither, so convert them before writing the view.
  4. Record simulate(), then encode(), then submit, once per tick.
  5. An emitter’s shape, curve, forces and capacity are fixed when it is added; only controls (rate, position, visible, eventsEnabled), burst() and a flocking emitter’s neighbours (avoid point, gains) change live.
14 more in brief
  1. Size pools for their own effect: each reserved slot costs 28 or 32 bytes of state plus 4 for its live id and rank scratch.
  2. Active emitters share one live budget in proportion to their capacities, so a million-slot layer beside a 2,000-slot one leaves the small one its share only while the total fits.
  3. Particle lights score every live particle of every emitter with light set, each frame: about 0.94 ms per 100,000 candidates on the reference laptop.
  4. Lights are chosen by brightness, then tiled on screen: your own surface shaders read them through PARTICLE_LIGHT_WGSL (group 3, binding 20), with the pixel position used to build the tiles.
  5. Clear the handover header after consuming the records (clearResting).
  6. Height collisions sample the end of each step: fast debris can cross a narrow ridge in one tick.
  7. Alpha emitters are sorted by their centres only: two large clouds that overlap can swap draw order as their centres pass.
  8. Flocking and fluid neighbours keep eight particles per hash bucket in slot order: set the radius to the spacing you want, or crowded cells undercount.
  9. Keep wind as velocity (flow) separate from acceleration (wind, windField): a steady gust added as acceleration speeds pollen up for ever.
  10. Keep mesh and path vertices in the emitter’s sector-local coordinates, and bump the shape’s revision after writing the buffer in place, or the old lengths and areas keep being sampled.
  11. Refresh an event producer’s count every tick, zero included: a stale count repeats the same births.
  12. Deposition counts in integer quanta: choose a quantum whose units times the pool capacity fit 32 bits, even if every particle lands in one cell.
  13. Clear the smoke medium’s volume history when the camera or the grid moves, or smoke is left at its old screen position.
  14. Read debug buffers with the reported stride (features.stride): f16 velocities (28 bytes) saturate at 65,504 m/s; positions and ages stay f32.
19 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Hannes Andersson: The HaTac engine’s particle runtime, its tests and measurements; the demo written for the library.

particlesgpu particlescomputewgslraw webgpuindirect drawprefix sumstream compactionmillion particlesemittersmesh emitterpath emitterfield emitterlife curvesbillboardstrailsribbonsflipbooksoft particlessparksembersfirefliessmokedust

Near it in the frame