Week 9: GPU Game of Life

screenshot

For my ninth weekly project, I’ve created…life!

Although it was originally computed by hand, Conway’s Game of Life has been implemented as software so many times over the past 44 years by so many people that I’m not sure doing my own version even counts as a creative project, but somehow throughout my decades of computer programming I’ve never built one, so I’m doing it anyway.

This particular version is implemented almost entirely on the GPU–the CPU provides the initial state and can turn more cells on to keep the game going, but otherwise all computation is done in a compute shader. (Compute shaders are kind of brilliant for this, as the Game of Life is practically the definition of an embarassingly parallel problem.)

I render live cells in red, and have dead cells fade gradually in green instead of disappearing. This makes it easier to see structures forming and vanishing. The initial condition is just created by randomly drawing pixels all over the buffer, and you can add more at any time by holding down the Enter key.

One thing I found particularly interesting is how many gliders tend to emerge from these completely random starting conditions! With the green trails behind them, they’re very visible. You also get a lot of small, stable structures as well as simple oscillators. (Phase-2 oscillators are almost impossible to see in this simulation, unfortunately, because it moves so fast it makes them look stable.)

Click here to download the program (update: added some DLLs it was missing). It’s a Win32 executable and requires a D3D11-compatible video card (anything even remotely recent should work). There’s some on-screen help-text that explains some other controls you can use.