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