Simulating 30 Million microbes in Browser
Simulating 30 Million Microbes in the Browser WebGPU gives the browser direct access to modern GPU capabilities — not just for rendering, but also for general-purpose computation through compute shaders. But how far can we actually push it? What happens if, instead of running a small compute demo, we try to build a full simulation with tens of millions of active objects? That is what I wanted to…
WebGPU enables browsers to harness advanced GPU capabilities, not just for graphics but also for general-purpose computation. To test the limits of this technology, a simulation of 30 million microbes was built using WebGPU. The original evolution simulator, written in C#, was adapted to run on the GPU instead of the CPU. This required careful memory management, as each cell needed various attributes like age, species, energy levels, and traits.
To optimize memory usage, the simulation state was split across multiple arrays, with different data stored in separate buffers. The simulation ticks were divided into stages, allowing cells to make decisions in parallel without worrying about the order of execution. Rendering 33 million cells directly on the GPU proved impractical, so the simulation data remained on the GPU, while JavaScript handled the UI and camera.
The resulting simulation could run smoothly with tens of millions of active objects, demonstrating the potential of WebGPU for complex simulations within a browser tab.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.