I've been playing around with cellular automata for procedural generation in WebGL. Here's an algorithm for rendering dendriform growth. I was aiming for rivers, but it came out like neurons.
It's built atop a diffusion-limited aggregation cellular automata. Algorithm sketch:
- Each cell looks at the 4 nearest neighbors on the grid. We also check the 4 corners ("far" neighbors) to avoid creating loops.
- Random numbers are provided by a separate noise texture
- State is stored in the channels of an RGBA texture. Each [0,1] channel maps to a [0,255] byte value
- The texture is seeded with at least one "active" pixel (existing water/lake/cell body). The seed is set to active (green=1.0)
- Green channel runs a a diffusion limited aggregation:
- If exactly one nearby pixel is active, then we have a 5% of becoming active.
- Avoid creating loops: don't activate a pixel if more than one "far" neighbor is already active.
- Because pixels act in parallel and at random, sometimes two pixels turn on in the same iteration, creating a loop. Detect and remove these after-the-fact, if they happen.
- Keep track of distance from the "seed" region in blue channel
- Seeds are initialized with blue channel = 255
- Newly activated cells get blue-1
- This counts down to zero, at which point expansion stops
- The texture is also initialized with various water sources / "synapses" scattered about it
- This is stored in the alpha channel
- If an active cell hits a source, it becomes a "river"
- If a cell is active, and an adjacent cell is a "river", and is also further away from the source (check distance in blue channel), then this cell also becomes a "river"
- A separate shader checks which cells are rivers, and generates tile ID values which are then passed to a tile shader.














