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.
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.
More by Jim
- Smear phishing: a new Android vulnerability
- A probabilistic pub quiz for nerds
- Time is running out to catch COVID-19
- The inception bar: a new phishing method
- The hacker hype cycle
- Project C-43: the lost origins of asymmetric crypto
- How Hacker News stays interesting
- My parents are Flat-Earthers
- The dots do matter: how to scam a Gmail user
- The sorry state of OpenSSL usability
- I hate telephones
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- Granddad died today
- Your syntax highlighter is wrong