Controls
Feed
0.0545
Kill
0.0620
Diff A
1.00
Diff B
0.50
Presets
Back to gallery
Experiment2026Three.js

Reaction-Diffusion on a Sphere

The same two warring chemicals as Gray-Scott, but running across the surface of an icosphere — every vertex reacts and diffuses with its mesh neighbors, all on the GPU. Nudge the feed and kill rates to slide between corals, mazes, and dividing cells.

Drag to rotate the sphere.

The reaction

This is the same Gray-Scott model as the flat reaction-diffusion field: two chemicals, A and B. A is fed in everywhere, B is removed everywhere, and where they meet the reaction A + 2B → 3B turns A into more B. Each point updates from its neighbors every step:

  • A' = A + (Dₐ∇²A − AB² + f·(1−A))·dt
  • B' = B + (D_b∇²B + AB² − (k+f)·B)·dt

Running it on a sphere

On a flat grid the Laplacian ∇² is easy — every cell has exactly eight neighbors in a tidy 3×3 box. A sphere has no such grid. Instead the surface is an icosphere: an icosahedron subdivided five times into ~10,000 vertices, each connected to six neighbors — except the twelve original corners, which keep just five.

Because the neighborhood is irregular, the Laplacian becomes an umbrella operator: the average of a vertex's neighbors minus the vertex itself. That single definition copes with both the five- and six-neighbor cases, so the math from the flat field carries over almost unchanged.

How it works

The icosphere and its adjacency are precomputed once when the page loads. Each vertex's A/B state is packed into a single pixel of a data texture, and a second lookup texture stores a pointer to each vertex's neighbors. Every step renders that state texture through a fragment shader that gathers a vertex's neighbors, computes the umbrella Laplacian, and writes the next state — two textures ping-ponged a dozen times per displayed frame.

To draw the result, the sphere's vertex shader looks up each vertex's chemical state straight from that texture, colors it through the same palette ramp as the flat field, and nudges the surface outward where chemical B is strong. When the device supports them, 16-bit float textures keep the gradients clean.

Thanks

The math, the parameter intuition, and the preset feed/kill values all come from Karl Sims' wonderful explainer, Reaction-Diffusion Tutorial.