NCA cactus growth stages

A WebGPU demo of Growing Neural Cellular Automata (Mordvintsev et al., 2020). Each cell in a 40x40 grid runs a shared pretrained neural network in a compute shader to update its state. The CA grows from a single seed cell and self-repairs when damaged.

Cell State and Perception

Each cell has a 16-channel state vector: RGBA + 12 hidden channels. The simulation seeds a single center cell (RGB=0, alpha and hidden channels = 1) and lets the network grow outward from there.

Each cell builds a 48-dim input by convolving its 3×3 neighborhood with three fixed kernels: identity, Sobel-X, Sobel-Y across all 16 channels. The Sobel filters give the network gradient information without requiring it to learn spatial awareness from scratch.

Network and Update Rule

Two linear layers output a delta added to the current state. Network weights are uploaded to GPU storage buffers once and shared read-only across all cells per step.

Two mechanisms from the paper govern the simulation: stochastic updates (each cell fires with 50% probability) and a life mask (cells with no alive neighbors are zeroed out).

WebGPU Pipeline

Compute and render passes run back-to-back each frame. Double-buffered state avoids read-write collisions.

You can draw on the canvas to erase cells. The pattern self-repairs: a core property of the neural CA.