Gray-Scott Reaction-Diffusion
Two virtual chemicals feed, react, and diffuse across a field running entirely on the GPU. Nudge the feed and kill rates to slide between corals, mazes, and dividing cells.
The reaction
Gray-Scott models two chemicals, A and B, spread across a grid. A is fed in everywhere; B is removed everywhere. Where they meet, the reaction A + 2B → 3B converts A into more B — an autocatalytic loop that's constantly fighting the feed and kill terms trying to wash it out.
Each cell updates from its neighbors every step:
A' = A + (Dₐ∇²A − AB² + f·(1−A))·dtB' = B + (D_b∇²B + AB² − (k+f)·B)·dt
The whole zoo of patterns lives in just two numbers — the feed rate f and the kill rate k.
How it works
The state lives in a texture — A in the red channel, B in the green. Each step renders a full-screen quad through a fragment shader that reads a cell's nine neighbors, computes the Laplacian, and writes the next state. Two textures are ping-ponged: read from one, write to the other, swap, repeat.
A single displayed frame runs the simulation a dozen times before drawing — the dynamics need many small steps to look smooth, and the GPU has them to spare. When the device supports it, the field uses 16-bit float textures for cleaner gradients, falling back to 8-bit when it doesn't.
Painting is just another write: while the pointer is down, the simulation shader stamps B to 1.0 inside a small radius around the cursor, and the reaction takes it from there.
Presets
Feed and kill carve out narrow bands of behavior, and small moves cross boundaries between completely different regimes:
- Corals — branching fronts that grow into and fill space.
- Mitosis — blobs that grow, stretch, and split into two.
- Spots — stable dots that settle into a loose lattice.
- Maze — winding labyrinth walls that never quite close.
- Worms — wriggling filaments that drift and reconnect.
Thanks
The math, the parameter intuition, and the preset feed/kill values all come from Karl Sims' wonderful explainer, Reaction-Diffusion Tutorial. If you want to actually understand what's happening here, read that first.