📚 Encyclopedia

Games & Graphics · updated 2026-10-13

2D tile-based liquid simulation (cellular automata)

cellular-automatawatersimulationterrariaminecraftnoita

How games simulate water on a tile grid, which model fits a 2D platformer, and the performance lessons from Run's liquid system.

Approaches compared

Approach Used by Pressure Cost
Levels 0-7 Minecraft none cheapest
Byte volume 0-255 Terraria none cheap, queue-based
Float mass + compression w-shadow.com, DwarfCorp implicit moderate
Per-pixel materials Noita (falling sand) density swaps expensive
Virtual pipes academic yes + waves moderate
Mass in kg, iterative Oxygen Not Included yes expensive

Each cell has a float mass (0 empty, 1 full, slightly above 1 = compressed). Constants: MaxMass 1.0, MaxCompress 0.02, MinMass 0.0001, MinFlow 0.01. Per cell per tick: flow down first (using the stable-state split), then left/right by (mass - neighbor) / 4, then up only if compressed.

stable_state(total):
  if total <= 1:              return total
  if total < 2 + MaxCompress: return (MaxMass^2 + total*MaxCompress) / (MaxMass + MaxCompress)
  else:                       return (total + MaxCompress) / 2

Compression gives pressure equalization without tracking pressure.

Gotchas

Run's implementation (a simpler, game-oriented variant)

See also

Linked from

Sources: run memory (research-water-physics.md, editor-v2.md, improvement-cycles.md)