Skip to content

Commit 36a073f

Browse files
save file
1 parent 8a35df4 commit 36a073f

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Conway’s Game of Life in WebGPU
2+
3+
This example demonstrates how to run Conway’s Game of Life entirely on the GPU using WebGPU. The simulation grid is stored in GPU buffers, and a compute shader applies the Game of Life rules in parallel across all cells. Each frame, the compute pass produces the next generation, and the result is uploaded to a texture for display on a canvas.
4+
5+
## How it works
6+
7+
The simulation uses a pair of GPU storage buffers to represent the current and next state of the grid. A WGSL compute shader reads from the input buffer, counts the eight neighbours of each cell, and writes the updated value into the output buffer. After each compute pass, the buffers are swapped so the new state becomes the input for the next frame.
8+
9+
## Rendering the grid
10+
11+
Once the compute shader has produced the next generation, the CPU converts the 0/1 cell values into an 8‑bit texture. A simple fullscreen quad shader samples this texture and displays the grid as white (alive) or black (dead) pixels. The canvas is scaled up with nearest‑neighbour filtering to preserve the blocky appearance.
12+
13+
## Why WebGPU is a good fit
14+
15+
WebGPU allows the entire update step to run in parallel on the GPU, which is ideal for cellular automata like Conway’s Game of Life. Even large grids can be updated at interactive frame rates because each cell is processed independently in a compute workgroup.
16+
17+
## What this demo shows
18+
19+
- Initialising WebGPU and creating compute pipelines
20+
- Using storage buffers to hold simulation state
21+
- Implementing Conway’s rules in WGSL
22+
- Running a compute pass every animation frame
23+
- Uploading results to a texture for display
24+
- Rendering the grid efficiently with a fullscreen quad
25+
26+
This makes a good starting point for experimenting with GPU‑accelerated simulations, cellular automata, or any system that updates a large grid of values in parallel.

0 commit comments

Comments
 (0)