Devlog / Entry 004 / Phase 3: Lights Out

Lights Out: ray-traced lighting for a gas station at night

Phase 3 is done: physical lights, ray-traced soft shadows, probe lighting, volumetric fog, a flashlight and a post stack, at 138 fps at 1080p on the laptop's RTX 4060.

23 Oct 2026 Phase 3

Phase 2 ended with a cube that both graphics APIs agreed on. Phase 3 is the renderer proper, and it ends in the dark: the greybox gas station at night, lit by its canopy floods, the shop's ceiling lights and the player's flashlight, with every shadow cast by rays.

The forecourt at night, from the player's eyes, in engine

That picture is rendered by the test suite, on Mesa's software Vulkan, so it is the same on every push. Everything in it is physical: the floods are 30,000 lumens each, the sky is a faint blue, the exposure is EV 5, and the tonemapper is the ACES curve.

Light in real units

Lights carry lumens or lux, and a surface answers with the metal/roughness model that every modern renderer shares: GGX for the highlights, Lambert for the rest. The camera has an exposure in EV100, the photographer's scale, so a night scene is dark because its numbers are small, not because something multiplied the picture by a fraction. The levels file sets all of it and hot-reloads, so moving a light is a save away.

Shadows from rays

Every pixel shoots a ray towards each light, straight into the frame's scene, through the ray queries that DirectX 12 and Vulkan both expose. The light's size makes the shadow soft: a ray aims at a random point on the source, so the edge of a shadow is a region where some rays hit and some miss. One ray per pixel per frame is noisy, so a denoiser follows: last frame's result is found again by reprojection and averaged in, then an edge-aware blur smooths what is left while the G-buffer's normals and positions keep it from smearing across edges. A second ray per pixel samples ambient occlusion the same way.

The denoiser taught me one lesson late. A canopy flood flickers, as failing tubes do, and the moment it did the shadows filled with speckle on the RTX 4060 while every test stayed smooth. The rays pass averages the lights' visibilities weighted by how bright each one is, so a light that dims three times a second changes the weights three times a second, and a running average of something that keeps changing never settles. Each light now carries its flicker fraction and the rays weight by the steady value. The tests never flickered, which is why they never caught it.

Light from the walls

Direct light is not enough at night; a floodlit wall lights the ground next to it. A grid of light probes over the level, two metres apart, handles that. Every frame each probe shoots sixty-four rays, sees what they hit and how far, and settles its small maps of irradiance and visibility towards what it saw. A surface then reads the probes around it, weighted by whether each one can actually see it, so light does not leak through a wall. This is the DDGI scheme that Nvidia published; the maps are octahedral, the visibility test is Chebyshev's, and the whole thing lives in two atlases that swap every frame.

Fog with beams in it

The air is a grid of small cells, froxels, that follow the view: a screen-sized grid of columns cut into sixty-four depth slices that grow with distance. Each frame every froxel takes the light that reaches it from every lamp, after a shadow ray, and scatters it towards the camera with the Henyey-Greenstein phase function. A second pass sums the froxels along the view, so a pixel then needs one lookup to know what the fog in front of it adds and how much of its own light gets through. The flashlight's beam shows in the air and stops at walls.

The flashlight

A spot light on the player's right shoulder, 900 lumens, with a cookie: a small texture projected through the cone that shapes the beam into a bright centre, a soft ring and a few rough edges, the way a real tactical light looks on a wall. The F key toggles it, and its shadows are the softest in the scene because the source sits so close to what it lights.

The lens and the film

The last pass is the camera itself, every effect its own switch. Temporal anti-aliasing nudges the projection by a fraction of a pixel each frame and averages the frames. Bloom halves the picture five times and adds the levels back up, so a light glows at every width at once; a procedural lens dirt texture catches only the strong glow. Depth of field, chromatic aberration, vignette and film grain are there for later, the grain so faint it lives only in the midtones. Night vision is an image intensifier tube rather than a green tint: the gain adapts to the scene's average light, the noise is photon noise that sparkles in the dark and goes quiet in the light, bright lamps saturate and halo, and the picture ends at the tube's round edge.

The same view through night vision goggles

Which GPUs

The decision I had put off: Night Warrant needs a GPU with ray queries. GeForce RTX 2060, Radeon RX 6600, Intel Arc, or anything newer. The rays carry the shadows, the ambient occlusion, the probes and the fog's beams, and a second rendering path for GPUs without them would have slowed every phase after this one. Both backends now prefer such a GPU when a machine has several. On anything else the game still runs, says so on screen, and shadows only the flashlight through a shadow map.

Performance

Full stack, 1920 by 1080, RTX 4060 laptop GPU 7.3 ms per frame, 138 fps
Fog 0.9 ms, after the summing pass; 3 ms before it
Denoiser about 1.5 ms
Probes about 0.6 ms

The target was 60 fps. The biggest single win came last: the fog used to march every pixel through up to sixty-four slices, and summing the froxels once per frame instead made it four times cheaper.

The numbers

Engine code about 16,700 lines in 11 modules, of which 4,900 are the renderer and its 1,800 lines of shaders
Tests 122 unit tests; the renderer tests draw pictures on llvmpipe and check their pixels
CI 7 builds per push (GCC, Clang, MSVC, AddressSanitizer, ThreadSanitizer), all green

Next: Through the Walls

Phase 4 is sound: an own mixer, 3D audio, occlusion, and a radio that sounds muffled behind a closed door and clear when it opens.