Slip & Diedevlog

Deep dive · Episode 6 ·

Twenty fires, three lights and a tree that waits for company

How fire spreads in Slip & Die: every burning thing sends heat, every fuel stores it and loses it, and a living tree ignores a lone fire until enough burns around it. Then the lights: why burning plants share a pool of a few point lights, why torches had to leave it, and how a torch's shadow went from about 2 ms to under 1.

A ruined temple at night with torches on its steps and dry shrubs burning on the grass in front of it

Every fuel stores the heat its burning neighbours send, leaks it and lights at its own threshold; a living tree also waits for a lot of fire around it.
Lights are the expensive part, so burning plants share two or three, and the torches got their own after the shared ones made the temple blink.

Shooting the temple torches made the whole level blink. The light pool we had built for fires was the obvious culprit. It was part of it, and not the main part. That comes at the end; first, how fire gets from one plant to the next.

Fire went into the game between 10 October and 5 November, over eleven test rounds (a round is a build I try, plus my notes on it).

Heat, not a grid

Fire usually spreads as a cellular automaton, a grid where each burning cell may light its neighbours. Our plants are not cells: a dry shrub is 2.2 m tall, an acacia is a tree. So every flammable thing carries a material, and every 0.1 s each fire sends heat to the fuels around it.

A fuel keeps the heat it receives and leaks it at a rate k per second, proportional to what it holds. That rate is the material’s moisture. When the stored heat reaches the material’s threshold, it lights. The leak sets a floor: a fuel settles at flow ÷ k, so it never lights if it receives less than threshold × k per second. A dry shrub at its peak sends 6 units per second at contact, so one lights a dry neighbour and a green shrub needs four burning against it. The floor of each material:

The heat falls off with the gap between the two plants, edge to edge, is pushed by the wind and helped uphill. A low fire only warms the foot of a tall plant, so a burning meadow alone does not light green shrubs or trees. Put a dry shrub 1 m from one burning at full strength, in a wind of 0.4 on a 0 to 1 scale: downwind it lights in about five seconds, upwind it never does.

Under the hood: the heat rule

The store. Each tick a fuel adds up the heat of every burning thing near it, times a factor for gap, wind, slope and flame height. The leak is integrated exactly, so the result does not depend on the length of the step:

let equilibrium = flow / cooling;
equilibrium + (stored - equilibrium) * (-cooling * dt).exp()

The time to light under a steady flow is -ln(1 - threshold × cooling / flow) / cooling: for a dry shrub against a burning one at contact, -ln(0.75) / 0.15, about 1.9 s.

The falloff. The heat that arrives is heat × (1 − gap/reach)² × wind, with reach = 0.6 m + 0.7 × flame height and wind = 1 + 1.5 × strength × cos θ, where θ is the angle between the wind and the direction from the fire to the fuel. For the example above, a 2.2 m flame: reach 2.14 m, falloff 0.28, downwind ×1.6 gives 2.7 units per second against a floor of 1.5, so 5.3 s; upwind ×0.4 gives 0.68, below the floor.

Trees that wait for company

With the heat rule alone a burning shrub could light a living tree, and a living tree could light the next one, and the fire would cross the level along the tree line. We wanted a tree to catch only inside a real blaze, and heat from one neighbour does not say how much is burning around it, so a second rule decides whether the heat counts at all. Each burning thing has a fuel load: 4 for a dry shrub or a burning living tree, 8 for a dry tree, 0.4 for a cell of dry grass. A living tree ignores every bit of heat until the burning load within 2.5 m of its edge reaches 24.

One dry shrub (load 4) does nothing to it. Three burning living trees make 12; even sixteen burning grass cells, the most that can burn at once, make only 6.4. Two dry trees with two dry shrubs make 24, and so do six dry shrubs. Green shrubs and green grass follow the same rule with lower bars, 14 and 8.

Two hard limits keep a tuning mistake from burning the whole level: at most 16 things in flames at once, the rest held at their threshold, and at most 12 hops from the first ignition. The benchmark further down places twenty fires by hand, above this cap, to measure the worst case.

The ground burns as a front

Grass has no entities: the GPU draws the meadow from a map. To burn it, cells 1.2 m wide are spawned around real fires, at most 400 per game.

The first burnt ground was a black disc under every fire, so a burning meadow became overlapping circles. Now each fire writes into a world-space field of 12 m tiles, 128 texels a side, so about 9 cm per texel. A texel stores when the black front reaches it and when the brown rim does. A grass cell burns away from the fire that lit it, so neighbouring cells continue one front. The grass map turns to short black stubble where the front has passed.

Who lights fires, and what puts them out

At first any seed that hit something dry could light it, with a 10-35% chance by material. On 14 October I decided that the plain seeds most guns fire never light anything: fire is left to explosions, the Limonsoffio and torches. Fires now start from explosions (up to six dry things in their radius), from the Limonsoffio, our acid flamethrower, and from torches knocked to the ground. Coals thrown by a falling torch can light what they land on, and so can coals from a fire taller than 60 cm. A lower fire’s coals light nothing, because a meadow lit by its own coals ran away in seconds, and a standing torch’s crackle never lights anything.

Nothing within 60 cm of water heats up, and in full rain a shrub burns out alone: the heat that passes drops by 85%.

Twenty fires, three lights

The first fires each had a point light, up to four, kept by the first four to catch, so a fire in front of the camera could stay dark. Lights are what Bevy’s clustered forward renderer pays for: every pixel is shaded with each light whose sphere reaches its cluster, so twenty fires with a 9 m light each make the ground around them twenty lights deep.

Now burning plants share a pool: no light on the Web-safe profile, two on Medium, three on Native-like and Ultra, none with shadows. Fires closer than 4 m share one light at their weighted middle, lumens added up to two fires’ worth. The groups brightest for the camera (lumens over distance squared) get the lights, and a group already lit counts 1.6 times brighter so that two almost level groups do not swap at every step of the camera. Beyond 45 m a fire gives no light, and from 31.5 m its light fades out.

On the test machine, a datacenter GPU from 2016 and our minimum-spec target, at 1280×720, we measured twenty fires at full flame, placed by the benchmark, as the GPU time they add over the same scene unlit. On Web-safe they went from 3.0 to 0.6 ms. On Medium they went from about 2 to 1.4 ms, and on Native-like, with water reflections off, from 3.5-3.7 to 2.2-2.4 ms. The same change drew the burnt ground only where fire can reach, so not all of it is lights. Web-safe has no fire light because one pooled light cost 1.1-1.5 ms there and none 0.6 ms, and only the second fits the 1 ms we allow fire on that profile.

The temple torches went into the same pool on 15 October; by November there were twenty-six of them. The pool was the first suspect, and rightly: at the time it had three lights for twenty-six torches, re-ranked every frame with no memory (the 1.6 bonus above came with the fix below). In one capture with three fallen torches, the pool’s lights jumped 10 to 23 m between two frames 21 times, each time darkening one patch of the temple and lighting another.

The torches left the pool. The nearest within 22 m carry their own light: eight at night on Native-like and Ultra, four at night on Medium, and at most four by day on any of them, when the sun drowns them anyway; Web-safe has no torch lights at all. A dark torch takes over from a lit one only when it is 3 m nearer. The plants kept the pool.

The blink stayed. The main cause was elsewhere. While a fire burns, the game writes the stubble into the grass map up to four times a second, and it wrote a new image asset each time. For the frame in which that image was not on the GPU yet, the floor lost its lawn and the grass its bind group: the ground showed bare for a frame, over and over, for as long as anything burned. In a 300-frame capture with fallen torches, 39 frames were bare. After the fix, none.

// Before: a new asset every 250 ms. The material points at an image
// the render world has not prepared yet, so for one frame there is no grass.
field.param_map = images.add(param_map_image(bytes));

// After: same handle, new bytes. The texture on the GPU is the same one,
// Bevy copies into it, and the bind groups reading it keep working.
images.insert(&field.param_map, param_map_image(bytes))?;

A shadow for under a millisecond

At night, on Native-like and Ultra, the nearest torch casts shadows that move with its flame. A shadowed point light renders a cube map, six views, which cost about 2 ms of render-thread CPU on the test machine whatever its range: 5 m and 3 m measured the same. Now the torch adds one spot light under its flame, looking straight down with a 75° half-angle, and the floor, the banana and the foot of the walls get their shadows from one view. The point light stays, without shadows, turned down to 70%, and the spot adds 1.2 times the torch’s light under the cone. Where the banana blocks the spot, only the 70% is left, and that difference is the shadow. Above the cone the dimmer point light is all there is. On the test machine at 1920×1009, at night with eight lit torches, the shadow’s render-thread CPU cost went from about 1.8 ms to under 1 ms. Runs differ by about 1 ms, so the second number cannot be read more finely. Only one torch gets a shadow: even on my PC the CPU, not the GPU, is the limit.

Still missing: in dry grass the burnt ground can run ahead of the flames as a dark, straight band. We slowed it down and have not redone it.

This is the technical companion to Episode 6: Shoot a torch and the jungle burns.

Spotted a mistake, or solved the same problem another way? Write to devlog@slipanddie.com.

← All episodes