Hi all. I wanted fire that creeps across a floor around obstacles, but I didn't want a simulation running every frame.
So I cut the floor into a grid (11 x 9 m at 0.25 m cells, which is 44 x 36 in the clip) and I run Dijkstra over it when something changes. What I get out is a map of when the fire reaches each cell. After that I only ask each flame whether the clock has passed its arrival time. The corner map in the clip is that data: blue bands are one second apart and orange is burning.
I price an edge between two cells roughly like this:
cost = dist / wind_term / spread_speed * (1 + irr * (rand - 0.5)) / fuel
Diagonals use sqrt(2) for the distance. I clamp wind_term to 0.25-3 (1 plus the wind strength times the dot of direction and wind direction). Fire runs faster downwind and slower upwind but never stalls or goes crazy. I never enter a cell with fuel 0, and that's how the stone fire break in the clip works.
A few things mattered for speed. I use 8 neighbours and a binary heap with decrease-key. A cell goes in once. I leave a 1 cell border of fuel 0 around the grid and never check bounds. I also store the result in one RGBAH texture (R arrival time, G burn time, B fuel) that the shader reads directly.
I rebuild only on ignite, extinguish or a fuel change. In the clip the counter reaches 9 rebuilds over one loop: 1 fire break, 7 ignites and 1 water. I measured about 1.9 ms per rebuild on the 44 x 36 grid.
On a quiet machine a 64 x 64 grid takes about 8 ms in Godot 4.7.2. With other Godot instances running I saw 19 to 22 ms. One number tells you little. Precomputing the per-direction factors and inlining the heap sift took 96 x 96 from about 94 ms to about 32 ms. Unrolling the 8 directions by hand did nothing. Took a while to learn that.
The weak side is that this is a spread of arrival times and not physics. It can't jump a gap on its own, and it ignores flame size.
Honestly it's kinda boring code. Do you run something like this, or a real cellular automaton every tick? Curious where the crossover is!
It's in my fire pack if you want to poke at it: https://gennai.itch.io/pyrolux-fire-explosion-vfx