DevLog #7 – Our campfire was a different fire at midnight. Now it casts shadows

Fire got rebuilt twice in the last two months. The first time on its own terms: how a flame is drawn, and what rain does to it. The second time because of DevLog #6. We replaced the sun with a physical model, the nights became properly dark, and the campfire in our first mission turned into a different fire after sunset. Along the way, fire also learned to cast shadows, which it had never done.

fire night hero Mission 1 at midnight. The only light in the frame is the fire, and every shadow on the ground comes from it.

Part one: the campfire looked like cut cardboard

The flame was orange and flat, with 1–2 pixel teeth chewing the whole silhouette. The teeth came from a phase offset that we read from a noise texture, per texel, so that the tongues of flame wouldn’t all rise in lockstep. The intention was right. But the offset varied along X, so neighbouring pixel columns ended up several full texture wraps apart. That’s textbook aliasing, and on screen it reads as a serrated edge.

The fix is to offset per particle instead of per texel. The detail worth keeping is that the shader can’t invent that number: there is no per-particle identity in the fragment stage, so the renderer has to send it, through a vertex stream. Two smaller fixes went into the same shader. The flame is now born inside its quad rather than on its bottom edge, which used to show as a ruler-straight line. And the edge softness is measured in screen pixels instead of texture units, so a fire 20 m away doesn’t go hard-edged.

None of that showed at first, because bloom was at zero and there was no tonemapper. The flame shader runs a blackbody model where the base is about ten times brighter than the tip, and all of it was being clipped to flat orange before it reached the screen. Turning the tonemapper on was not a fire change. It changed the colour of every surface in the game, so we treated it as a global change, not as a particle tweak.

The last piece is for daytime. At noon a fire can’t compete with the sun, and it becomes a decal on the grass. What still reads is the air above it moving, so there’s now a heat-shimmer pass that distorts the background. Its strength goes with intensity squared, so a dying fire stops boiling the air. Rain kills it, and so does night, for reasons that come up below.

Part two: a fire that could be neither lit nor put out

The simulation is a handful of rules. Rain takes intensity away at a rate quadratic in how hard it’s falling: a drizzle barely bothers a well-built fire, a downpour kills it fast. A roof scales that down. When it isn’t raining, the fire comes back, deliberately slower than it went out, because lighting a fire is work and putting one out is easy. Every rule was reasonable. Two outcomes were not.

The bucket of water lasted thirty seconds. Putting a fire out set its intensity to zero, and the next frame the rekindle rule started bringing it back. On dry ground it was burning at full again half a minute later. Two pieces of code, each doing exactly what it said, and the one that ran sixty times a second won. A fire put out by hand is now latched: it stays out until something explicitly relights it.

The value that neither rose nor fell. Recovery is gated by ground wetness, so soaked wood doesn’t relight itself. Correct. But after a shower there’s a state where it isn’t raining and the ground is still wet, and in that state both rules return zero. The fire held whatever value it had at that instant, to three decimal places, for the three to eight minutes the ground took to dry. And since wetness is global, every fire on the map froze at once, each at its own arbitrary level.

fire dead zone A 30-second shower over soaked ground. The dashed line is what the fire used to do afterwards: nothing.

The fix wasn’t a constant. It gave the fire somewhere to go: an explicit equilibrium, the intensity the wood can actually sustain at that wetness. There are three regimes now and only one runs at a time: rain falling, recovering toward that level, or decaying toward it. The fire is always heading somewhere. A fire caught by a shower and then left alone now dies about fifty seconds later, unless someone feeds it.

The part that stayed with us: the recovery rate had been carefully tuned to a 26–33 second window, with a comment explaining why. The wetness decay had been tuned just as carefully, in another file. Nobody had multiplied the two, and the product said that window described a case the other system never allowed to happen. The tests were there and they passed. A unit test can’t see a constant living in another file.

Then we replaced the sun

After DevLog #6 the campfire in mission 1 looked fine at noon and broken at midnight: thin, whitish, with orange blotches floating around it. We measured it in play and found five separate causes, and most of them were not in the fire itself.

fire night before after The same fire, same camera. Left: midnight before. Centre: noon. Right: midnight after. The flame matches noon; only the light around it changes.

  • Night vision was applied to everything. The new cycle desaturates and cools dark scenes, the way the human eye shifts to rod vision at night. It was applied to the whole frame, flame included. It now depends on luminance: full effect below 0.015 in linear scene luminance and none above 0.12. Moonlit ground sits at 0.005–0.03 and the edge of a flame at about 0.2, so the grass goes blue-grey and the fire keeps its colour.
  • An additive flame on a lit floor. The flame was added on top of whatever was behind it. At night, the brightest thing behind a campfire is the ground the campfire is lighting, so the sum saturated to white. The flame is now premultiplied with 85% occlusion: it covers the background and keeps its own colour.
  • The heat shimmer repainted the ground over the flame. It redraws the background, slightly displaced, on top of everything. At night that background is red-lit ground, hence the orange blotches. Shimmer now fades out with the night. It exists to sell a fire at noon; at midnight the fire’s own light does that job.
  • The fire was burning down. It consumed its wood over ten minutes and stepped down to a smaller model, so by the time night came it was a different fire. The mission’s campfire is a set piece and now stays as it is.
  • The logs shadowed themselves. More on that below.

fire night before after Noon, sunset, midnight. That was the requirement: the fire looks the same at any hour, and the lighting is the only thing that changes.

Fire that casts shadows

DevLog #6 ended with an admission: lights other than the sun cast no shadows. That’s fixed. But a point light with shadows renders the scene six times, once per cube face, so with a hundred units carrying torches, shadows for everything would sink the frame rate. So there’s a budget. Every 0.3 seconds the game picks the nearest lit fires, torches and lanterns within 70 m of the camera, and only those cast shadows: none on the low preset, two on medium and high, six on ultra.

fire shadows off on The same frame with zero and six shadow-casting lights. On the right, every man and every log throws a shadow straight away from the fire.

Two lights sitting inside geometry needed fixing first:

  • The campfire’s own logs. The light sits in the middle of the woodpile, so the logs and stones around it threw black spokes across the ground. Its shadows now start 1.2 m from the light. The pile casts nothing; a man sitting next to it does.
  • The torch inside the body. A unit’s torch was positioned on its own axis, which put the light inside the model. With shadows on, that drew dark patches around the unit’s feet. The flame is now in the hand: 45 cm to the side and 1.7 m up, or 75 cm out and above the horse’s neck for riders. Artillery crews carry no torch at all. Nobody with any sense walks next to the powder with a lit one.

Torches still don’t give vision, and that’s deliberate. If they did, every unit would be its own island of light and night would stop mattering. A torch lights your feet, not the horizon. To see at night you build a watchtower, light a fire, or accept that you can’t.

The three promises we’d made the fire

At the end of the first rework we’d written down three things the fire still got wrong. All three are done.

  • It ignored roofs. The weather system already knows what’s under a roof, because rain needs it, and it updates when a building goes up or comes down. Fire now asks it every 0.75 seconds and takes whichever is more sheltered, the roof or the value set for that fire. The fire’s own model and smoke are left out of that check; otherwise a campfire would count itself as a roof.
  • Wind didn’t touch intensity. It tilted the flame and dragged the smoke, and that was all. The real curve has a hump: a breeze feeds a fire, and a gale strips heat off faster than the wood produces it.
  • The flame had no inertia and the smoke did. A gust stepped the flame’s tilt from one frame to the next while the smoke column bent smoothly, and they visibly disagreed. The tilt now has a 0.25-second lag.

fire wind hump Plotted from the game’s fire code. A 5 m/s breeze lifts damp wood from 0.60 to 0.70. From 12 m/s the wind wins, and a gale leaves half a flame. Above 18 m/s you can’t light a fire in the open at all.

The smoke got a pass too. It’s lighter when the fire is burning cleanly, dark when it’s choking, and turns to white steam in the rain. It starts 55 cm above the base and draws behind the flame, so it doesn’t cover the flame.

What’s still missing

  • Heat shimmer is too strong. At noon, a unit standing right behind the fire gets smeared, and the shimmer leaves dark patches on a wall behind it. It needs a lower ceiling and a shorter reach.
  • Six shadowed lights is 36 extra renders during a big fire on ultra. It’s fine in our test missions, but a burning village is the case we’ll profile next.
  • Rain on the mission 1 campfire. That fire is a set piece, so the weather doesn’t touch it. Other fires do react.