
The goal
You see the living room fireplace up close in a dark, quiet moment, so flat particle sprites would've looked fake. I wanted flames with actual volume that look right from any angle and sit properly behind the logs.
How it works
The flames are a shader that ray-marches through a box sitting over the logs. For every pixel it takes 22 steps through the box, and at each step it works out two things: how thick the fire is there, and how hot.
1. Shape
It starts with the footprint, an oval over the logs that narrows towards the top and fades out towards its edges. On its own that's just a glowing cone. To break it up, I sample a 3D noise texture (64 by 64 by 64, the same one my steam uses), stretched tall and scrolling upwards. The lookup position is first pushed around by another sample of the same noise, which is called domain warping and makes it swirl. The result is then folded into ridges (ridged noise), so you get separate strands.

The trick that makes tongues is a cut-off that rises with height. Near the bottom almost any noise keeps the fire alight, but higher up it takes more and more, so only the strongest strands make it to the top.
// the bar to clear: 0 at the base, rising with height
float cut = h / _HeightFade;
// 1.7 lifts the noise so the base clears the bar easily
// _Sharpness sets how crisp the tongue edges are
float d = saturate((noise * foot * 1.7 - cut) * _Sharpness);
Because the footprint fades towards its edges, the edges fail the cut-off sooner than the middle. That's why the overall shape is a cone, with the noise deciding where the tongues are.
2. Colour from temperature
Each point also gets a temperature. It's highest where the fire is thick and low down, and it drops as the flame rises or thins out, so the tips and the edges both run cooler. That picks a colour from a three-stop ramp: yellow, orange, then dark red. The hot end is stored brighter than the screen can show, so where many steps stack up the core burns out towards white. No textures are involved in the colour at all.


3. Marching through the box
Stacking all 22 steps along each ray gives the final volume. The flames are mostly see-through, so each step only dims the fire behind it a little, and the colours add up. With so few steps you'd normally see bands, so each pixel starts its ray at a slightly different offset, which turns the bands into fine grain. The noise keeps scrolling upwards, so the tongues lick, and the overall brightness wobbles by up to about 12% on top of that.

Each step is at most three noise lookups. Steps outside the footprint skip them, and only the pixels the box covers on screen pay for any of it.
Since it's a real volume and not a flat card, it holds up as you move around it.

4. Sitting in the scene
The shader only adds light on top of the scene, so it never darkens what's behind it, and bloom takes care of the glow. Each ray also reads the camera's depth texture and stops where it hits the scene, so the logs and grate sit in front of the flames without any extra setup. The fire fades out over the last 3 cm before a surface, so there's no hard line where the two meet. It's driven by the same script as my steam and smoke, which can fade it in and out.
The diagrams on this page were rendered with a Python port of the shader, using the game's own 3D noise texture and the fireplace's saved settings.