Learn more about Russian war crimes in Ukraine.

Simulating epidemics in WebGPU

A few days ago, I simulated an epidemic with WebGL, using a texture for the state of a cellular automaton. However, I got some pretty weird effects. For example, the number of infected people never dropped to zero, despite the math clearly demanding that it should drop to zero.

I concluded that these weird effects were due to my sin of a texture to keep the state of the cells. The texture2d function lets you sample the color of a texture at a specific coordinate. Not a pixel; a coordinate. It does some clever stuff, like mipmapping, “level of detail”, and interpolation. For a cellular automaton, I need a lower-level API, to just access the value at a specific pixel in the texture.

As an extreme solution, I’ve rewritten the epidemic simulation in WebGPU. Earlier, I implemented Game of Life in WebGPU, and I modified that for my epidemic simulation. The API is much more pleasant: instead of the voodoo texture2d function to access pixels of a texture, I can instead directly index into an array of cells.

Gladly, the weird effects are not present in the WebGPU implementation!

Below you should see the simulation -- but probably only if you’re running Google Chrome Canary, and you’ve enabled the “Unsafe WebGPU” experiment.

What can computers do? What are the limits of mathematics? And just how busy can a busy beaver be? This year, I’m writing Busy Beavers, a unique interactive book on computability theory. You and I will take a practical and modern approach to answering these questions — or at least learning why some questions are unanswerable!

It’s only $19, and you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

After months of secret toil, I and Andrew Carr released Everyday Data Science, a unique interactive online course! You’ll make the perfect glass of lemonade using Thompson sampling. You’ll lose weight with differential equations. And you might just qualify for the Olympics with a bit of statistics!

It’s $29, but you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

More by Jim

Tagged #programming, #webgpu, #epidemiology. All content copyright James Fisher 2020. This post is not associated with my employer. Found an error? Edit this page.