PulsarPulsar
← Back to blog

rust

How Global Illumination Works in Pulsar, Held Up Against a Path Tracer

The whole indirect lighting path in Helio as it stands today, from the probe clipmap to the deferred lighting that consumes it, followed by a camera by camera comparison against the engine's own path-traced reference, what each setting costs, why one scene looked flat, and the two bugs the comparison found.

··29 min read

Some of our renders looked flat. Mesh scenes in particular could come out with the look of a much older console: surfaces evenly grey, shadows without depth, nothing much to hold the eye. A complaint like that has two very different possible causes. Either the lighting is wrong, and the renderer is failing to put light where light should be, or the lighting is fine and something after it is squeezing the picture. Arguing about which one it is from screenshots gets nowhere, so we did the thing a path tracer exists for. We rendered the same views twice, once with the real-time renderer at several settings and once with the reference path tracer that lives in the same engine, and put them side by side.

This post is the result, and it is also an up to date description of how global illumination works in Pulsar. We described the core of the rewrite in Indirect Light at a Pixel, which has the derivations, the history of the faults that shaped it, the credits to the published work it stands on, and accuracy and cost figures on other scenes. Here we walk the whole path once more as the code has it now, including the parts that post did not cover, such as traced reflections, how different kinds of geometry answer rays and what the lighting pass does with the answer, and then spend the rest of the time looking at pictures.

⚠️
Important

Every timing and error figure in this post comes from one scene, Sponza with the add-on curtains, rendered at 2560 by 1440 on an RTX 4090 with the editor open and holding roughly 10 GB of video memory, 18 to 21 GB in total during the runs. Treat the milliseconds as measurements of that machine on that day. We have not measured on an RTX 3060, and any figure we give for one is an estimate and says so.

1. The Shape of the System

Global illumination in Pulsar is a plugin, pulsar.gi. The renderer's core knows nothing about it, and a project that disables it gets a frame that draws without it. The plugin has one render feature, a probe clipmap and everything built around it, and it does not know what kinds of geometry or lights exist in the world either. Geometry answers its rays through ray streams: GI writes a buffer of rays, and whichever kinds of object are in the project each trace that buffer against their own representation and write back the nearest hit and the surface there. Lights answer through light samplers in the same spirit, with the sun among them. A new kind of geometry that wants to be seen by GI registers a tracer, and nothing in GI changes.

In a frame the work sits right after the G-buffer is filled. The probe pass writes this frame's probe rays, the radiance cache writes the rays for the surface cells it intends to light, and the tracers of each geometry kind answer both streams. A lighting pass shades the hits and asks the light samplers for a light and a shadow ray, the shadow rays go back through the tracers, an integration pass turns the results into probes, and the cache folds its results into its cells. The per-pixel gather, the denoiser, the resolve and the traced reflections follow, and only then does deferred lighting run and read what all of this published.

2. Probes

The foundation is a clipmap of six cubic grids of 24 by 24 by 24 probes centred on the eye. The finest grid has a probe every half metre by default and each level doubles the spacing, up to 16 m, so the half extents run from 6 m to 192 m. Probe positions are multiples of the spacing in world space and storage is toroidal, so a grid that scrolls with the camera only resets the probes that came into range.

Each probe is 72 words. It holds irradiance divided by pi as first-order spherical harmonics in half floats, a state, and an 8 by 8 octahedral map of the mean and mean square of the distance its rays travelled in each direction, the visibility test of DDGI. A frame updates 680 probes on each of the two finest levels and 340 on each of the other four, 2,720 in all, with 64 rays each along a spherical Fibonacci set turned by a new random rotation every frame, which comes to 174,080 probe rays. A new probe averages its first updates evenly and then settles into a hysteresis of 3 percent for irradiance and 5 percent for the distance moments. Once a probe has light, a single ray's radiance is capped at 16 times the probe's mean irradiance over pi plus 2, which keeps one lucky hit from lighting a probe by itself. A probe for which a quarter or more of the rays meet the insides of surfaces is buried and takes no weight. Nothing moves it out. A probe also holds its old value when none of its rays hit anything or when a tracer reports that it could not finish answering, and one consequence we know about is that a scene emptied of all geometry keeps its old probes.

A surface point reads the finest level that holds it. Eight probes contribute, each weighted by trilinear position, by how much the surface faces it, and by the Chebyshev test of the point's distance against the probe's distance moments, sharpened to the third power. The point is first pushed a fifth of the probe spacing along its normal so that it does not shadow itself, and near the edge of a level the result blends into the next, coarser one.

3. The Radiance Cache

A ray that hits a wall needs to know how brightly the wall is lit. The probes are a poor answer, since the nearest probe floats somewhere in the air, and tracing a whole path from every hit is too expensive. The radiance cache is the answer in between: a hash table over world space that holds the irradiance arriving at small patches of surface, with the direct and indirect parts kept apart. A reader multiplies the cell's irradiance by the albedo of its own hit, so cells carry no texture detail and can be fairly large.

A cell is identified by its place in the world as a 64-bit integer cell, its size level, the dominant side of the surface and the coordinate space the ray travelled in. Sizes are powers of two from 2 to the minus 6 metres to 1,024 m. Which size a reader asks for depends on how wide its ray is where it lands and on how far the hit is from the eye, whichever asks for the coarser cell. By default a cell spans about 40 milliradians as seen from the eye, 52 pixels at 1080p with a 45 degree field of view. The table has buckets of 16 slots, 2 to the power 18 slots by default at about 162 bytes each, 40.5 MiB, and cells that nobody has asked about for 128 frames are dropped.

Each frame has a budget of 32,768 rays for the cache, four per cell it chooses to light. Cells that have never been lit come first, then parts that are restarting after a change, then a slow refresh that visits every cell in turn, then cells still converging. Direct and indirect irradiance are plain means over as many updates as it takes to bring the relative standard error to 3 percent, between 16 and 64, while the light that has bounced averages 16 updates so that later bounces settle quickly. A fast mean over the last four updates is compared with the long history, and when they disagree by four standard deviations and by 1 percent the cell starts again, which is how a switched lamp or an opened door gets through.

Two rules keep the cache honest. Only the reader that serves the screen may create cells, which is the pixel gather when it is on and the probes when it is not; everyone else reads what exists and lights a miss on the spot. And each cell records, in eight directions along its surface, how far its rays found nothing in the way, so that a coarse cell straddling a thin wall does not hand the light of one side to the other. A read that comes up empty reports why, as a cell that is absent, new, unexplored in that direction or occluded, and the renderer's statistics count them. In one frame of our atrium view, a little over half of the cache reads made for probe ray hits found a value, and about four in ten found no cell at all and lit the hit directly.

4. One Ray for a Block of Pixels

The probes alone have a resolution of about half a metre. For anything finer, the quality setting lets rays start at the pixels themselves. It has four values, probes, pixels_16, pixels_4 and pixels_1, which mean no gather, or one ray for every block of 4 by 4, 2 by 2 or 1 by 1 pixels at the internal render resolution. The default is pixels_16. The gather serves the primary view.

Within a block the traced pixel rotates over frames and sends one cosine distributed ray about its G-buffer normal, with directions from an R2 sequence shifted per texel by a hash. The hit is lit from the radiance cache, plus a light sample and a shadow ray of its own. A single ray per block cannot see occlusion that is smaller than the block, so a second term handles that: for every pixel a horizon search over the depth buffer, along four slices in both directions and out to the width of the block, estimates how much of the hemisphere is open. Each pixel is then scaled by its own openness divided by the mean openness of its block. This moves light between the pixels of a block and leaves the block's total alone, so it adds contact detail without darkening anything twice.

The rays are reused through ReSTIR GI. Each traced pixel keeps a reservoir of 48 bytes holding the sample it chose. A new ray competes against last frame's sample, weighted as at most eight samples, and against four neighbours within three texels. A reused sample gets a visibility ray, because a neighbour may be on the other side of a wall. One texel in four also traces its previous sample again, and if the light there has moved beyond the cache's own noise, both the reservoir's weight and the confidence passed to the denoiser come down, so a change in lighting reaches every reservoir within four frames.

5. Denoising

The denoiser is shared infrastructure with a contract: a producer hands over a signal, its hit distances and optionally a confidence, and gets back the filtered signal. For GI the signal is irradiance encoded as first-order harmonics of luminance with two chroma terms. The pass reprojects the previous frames, accumulates for as long as the geometry says the history is valid, reconstructs widely where the history is short and finishes with two edge-aware filter passes. Its one firm rule is that no weight may depend on how bright a sample is. Weighting by brightness is a common way to tame noise, and for a signal made of rare bright hits among many dark ones it also removes light, which then compounds through the history.

Where a pixel has fewer than 16 samples' worth behind it, for example just after something moved out of the way, the resolve leans on the probes' irradiance as a prior for the missing part. This happens after the denoiser and is never written back into its history.

6. Traced Reflections

Rough indirect light is only half of the indirect light. The gather above handles the diffuse part, and glossy and mirror surfaces get a ray of their own, sampled from the visible normals of the GGX distribution. By default one ray covers a 2 by 2 block, with a full rate setting that gives every pixel one, and surfaces rougher than 0.5 are left to the other reflection sources, with a blend over the last quarter of that range. A hit that is visible on screen can take its colour from last frame's lit picture, which is on by default and means those reflections include the camera's own view of highlights and run a frame late. Any other hit takes the radiance cache's direct and indirect irradiance through the surface's diffuse lobe, plus its emission, plus a specular term from further bounces or from the probes. The number of extra bounces defaults to zero and can be raised to three. The result goes through its own radiance denoiser and joins the other specular layers in deferred lighting. Traced reflections are not yet available in secondary and forward views, and glass reflections are not traced.

7. How Geometry Answers Rays

The ray streams are small and plain. A ray is 32 bytes, a hit 16 and a surface 32. GI names no geometry kind anywhere, and the two tracers in the engine today work quite differently.

Meshes use hardware ray queries against the frame's top-level acceleration structure. Cut-out materials are alpha tested at the mip level matching the ray's footprint, thin transmitting sheets let rays through, occlusion rays accumulate transmittance, and the surfaces at the hits are evaluated in a separate pass grouped by material program so that each shader runs coherently. Voxel worlds need no hardware ray tracing at all: a compute shader walks the same level-of-detail cut that is being drawn. Its pipelines compile in the background, and until they are ready the voxel tracer says its answers are incomplete, which is one of the cases in which probes hold their previous values. The Sponza measurements below exercise only the mesh path, on DirectX 12.

8. What the Lighting Does With It

Deferred lighting starts every surface with the sky's ambient irradiance multiplied by the diffuse reflectance of its material. Where the frame's indirect diffuse covers the pixel, that traced value replaces the sky term, blended by its coverage, so the sky no longer shines into places the world hides it from. The result is multiplied by the material's own ambient occlusion and added to the direct light. Specular layers, which are environment probes, screen-space reflections, planar and traced reflections, are composited with the split sum approximation, and are occluded by the same material term.

One thing is deliberately absent. There is no screen-space ambient occlusion pass, and the unused input that lighting once had for it is gone. The occlusion you see in the pictures comes from the traced rays, the near-field term of the gather and the occlusion painted into materials. In Sponza that last one contributes little, as the debug captures further down show.

9. A Path Tracer in the Same Engine

The reference mode is a progressive path tracer that shares the engine's scene, materials, tracers and light samplers. It traces its own camera rays from the eye, jittered within each pixel, follows nearest hits with full surface data, samples lights at every vertex with shadow rays and multiple importance sampling, ends paths by Russian roulette and accumulates in 32-bit floating point. It has no radiance cache, no denoiser and no clamping, and it restarts whenever the camera, the scene or the image size changes. It has a full view and an indirect diffuse view.

We drove the engine's renderer from a test harness that loads the project's level, fixes the camera and exposure at EV 0, waits for textures to be resident, lets each setting settle and then reads the frame back. There are three cameras in the Sponza atrium level with curtains: atrium, looking down the length of the building; corridor, along a shaded side gallery; and contact, close on the foot of a curtain beside a column and wall. For the comparison we turned off the level's fog and lens effects in a copy of the level, since the reference models neither in a way we could compare.

Both sides of the comparison are scene-linear frames run through a port of the engine's AgX punchy tone curve and nothing else. That matters, because the engine's own output also applies local exposure, which is a large part of the story in section 12. To check the port, we turned local exposure off in the level and compared the engine's own output with ours; they agreed within 0.1 to 0.7 levels out of 255 on average.

The reference accumulated up to 796 samples per pixel for each camera, 5,600 frames or about three minutes a view. Its remaining noise, measured as the difference between the half-way and final images, is a mean of 0.20 to 0.30 levels over the whole frame, so differences of a few levels between settings are real. We report the mean absolute luminance difference in 8-bit levels, its 95th percentile, and the same mean over shaded pixels only, meaning surfaces that receive almost no direct light in the project's settings. Those are the pixels where indirect light is nearly everything. The masks are in the appendix, white where a pixel counts.

10. The Comparison

The settings under test are these. The project as we found it used pixels_4, full rate reflections, a render scale of 0.75 and temporal super resolution (TSR) off, and we call that variant A. The others change one or two things around it.

variantgatherrender scaleTSR
A, the project's settings1 ray per 4 pixels0.75off
Approbes only0.75off
P1probes only1.0native
B1 ray per 16 pixels1.0native
C1 ray per 4 pixels1.0native
D1 ray per pixel1.0native
EGI off1.0native
T1 ray per 4 pixels0.75quality

Errors against the reference are below, each cell being mean, 95th percentile and, after the slash, the mean over shaded pixels with its signed value in parentheses. A positive sign means brighter than the reference.

variantatriumcorridorcontact
A5.34, 17.5 / 3.51 (+3.34)2.22, 8.0 / 1.14 (+0.96)2.47, 12.9 / 0.22 (-0.14)
Ap7.08, 21.3 / 6.52 (+6.37)1.94, 8.0 / 0.76 (+0.51)2.53, 13.1 / 0.23 (-0.10)
P15.86, 21.1 / 4.89 (+4.65)2.18, 8.9 / 1.01 (+0.76)2.65, 14.1 / 0.23 (-0.12)
B4.03, 18.2 / 1.30 (+0.81)2.00, 8.8 / 0.81 (+0.57)2.59, 14.0 / 0.22 (-0.16)
C4.52, 18.5 / 2.03 (+1.80)2.13, 8.7 / 1.00 (+0.80)2.59, 13.9 / 0.22 (-0.16)
D4.83, 19.0 / 2.58 (+1.60)2.84, 11.8 / 1.66 (-0.54)2.84, 14.4 / 0.51 (+0.16)
E9.43, 28.1 / 13.88 (+13.72)5.34, 20.8 / 4.31 (+2.99)6.17, 24.0 / 6.37 (+6.16)
T4.06, 16.9 / 1.81 (+1.48)2.04, 8.0 / 0.99 (+0.78)2.48, 13.3 / 0.22 (-0.16)

The first thing the table says is that the lighting is not what is broken. With GI on, every variant tracks the reference to within a few levels on average. With GI off, the shaded parts of the atrium are almost 14 levels too bright and the contact view over 6, because a flat sky ambient fills every corner whether or not the sky can reach it. That is the older console look in its pure form, and global illumination is what removes it.

10.1 The Atrium

Path-traced referenceA: project settingsA: project settingsPath-traced reference
⇆
Path-traced referenceE: GI offE: GI offPath-traced reference
⇆

The difference images make the pattern easier to see. Each shows the reference at a quarter of its brightness, with four times the difference added in red where the real-time frame is brighter and in blue where it is darker.

In the atrium, A reads brighter than the reference in shade, with a mean shaded indirect of 0.0077, 0.0064, 0.0064 in exposed linear RGB against the reference's 0.0063, 0.0051, 0.0044: too bright and a little blue. GI off gives 0.0218, 0.0200, 0.0209, more than three times the reference. The probes alone at 0.75 sit in between at 0.0111, 0.0093, 0.0089. One in 16 at native resolution, B, had the lowest shaded error here, lower than the settings with more rays, and we do not take that to mean fewer rays are better; D's numbers point at something specific, covered below.

10.2 The Corridor

Path-traced referenceD: one ray per pixelD: one ray per pixelPath-traced reference
⇆

The corridor holds the clearest result we cannot explain. Tracing a ray for every pixel, D, comes out too dim and distinctly blue in shade. Its mean shaded indirect is 0.0026, 0.0033, 0.0050 against the reference's 0.0067, 0.0056, 0.0045, so the red is well under half of what it should be while the blue is slightly over. At one ray per four pixels, C, the same shaded pixels are 1.0 level off and slightly bright, like the other settings, so this is particular to pixels_1. The contact view shows the same blue shift. We have not found the cause.

10.3 Contact

Close up, the largest differences from the reference are in direct light and not in GI. The real-time sun shadow edges are softer, some inner folds of the curtain receive direct light where the reference leaves them black, and a thin seam runs along the base of the wall. In the brightened sheet the light in the folds is already there in the direct-only layer, while the seam shows in the combined frame and in neither the direct-only nor the indirect-only one. We have not isolated the cause of any of the three. Because the reference is nearly black in this shade, the shaded error stays small for every setting with GI on, and there is little here that a screen-space occlusion pass could have fixed.

10.4 Cloth, Columns and Resolution

At middle distance the cloth shows a regular stipple that the reference does not. The reference is effectively supersampled, so aliasing of the fabric's normal map is a natural suspect, but we have not confirmed it. These were also still frames. How TSR behaves with a moving camera is not covered by anything here.

11. Inside a Frame

The editor's debug views let you take a frame apart. These are the project settings in the atrium.

1 / 11
Albedo: the base colour textures alone, with all their wear, before any lightUse arrows or ← →

The view comparing GI with the sky ambient is the one that explains the GI-off error best. It is mostly red: almost everywhere in this building, the honest indirect light is darker than an unoccluded sky would have been. The exceptions, in green, are parts of the floor and some curtains, which receive more from sunlit surfaces than the sky alone would give.

12. Why It Looked Flat

If the lighting tracks the reference, the flatness has to come from somewhere else, and it does. We built a ladder of three real-time images and the reference for each camera: the level exactly as saved, then with fog and lens effects off, then with local exposure off as well.

Engine output, local exposure offEngine output, local exposure on (default)Engine output, local exposure on (default)Engine output, local exposure off
⇆
Fog and lens offThe level as saved, with fog and lensThe level as saved, with fog and lensFog and lens off
⇆

Local exposure adjusts exposure per region of the picture. It builds a bilateral grid of log luminance, 24 bins of one stop, fits a monotonic tone curve per cell and uses it to compress contrast around middle grey, with separate strengths for shadows and highlights. By default the shadow contrast is 0.5, highlight contrast 0.85 and detail 1.0. At those defaults, the engine's output averages 20 to 26 levels brighter than the same frame through the tone curve alone. In the pixels the plain curve shows below level 20, which are 54 to 79 percent of these frames, the average goes from between 2 and 5 up to between 19 and 35. Deep shade that carried the whole sense of depth in the picture is lifted into an even grey. The level's fog then lays a veil over the top, strongest in the atrium.

So the answer to our question is that the flat look is mostly post-processing: the default local exposure and the level's fog. The other side of that coin is that without local exposure these interiors are very dark, which the third and fourth images of each ladder show plainly, and the reference agrees with them. How much to lift shadows is an artistic decision and not something a path tracer settles. Setting shadow contrast closer to 1.0 costs no GPU time.

13. What It Costs

GPU frame times at 2560 by 1440 output, median over the measured window, for atrium, corridor and contact. The right column sums the GI and denoiser passes.

variantatrium, mscorridor, mscontact, msGI and denoise, ms
Ap, probes at 0.756.86.46.02.0 to 2.4
P1, probes native10.39.89.3about 4.1
A, 1 in 4 at 0.7510.19.59.0about 5.6
T, 1 in 4 at 0.75, TSR quality10.89.89.7about 5.7
B, 1 in 16 native13.312.412.0about 7.9
C, 1 in 4 native15.715.214.6about 9.8
D, every pixel native18.216.415.9about 14.6
E, GI off, native5.95.04.60

The 95th percentile frame is roughly 13 to 14 ms for A, 17 ms for B, 19 to 20 ms for C and up to 23 ms for D. Fresh runs of the same setting vary by about 0.5 to 1 ms, so the difference between A and T is at the edge of what these runs can resolve. The level as saved, with fog and lens, adds about 1 ms to A. Part of the cost in these frames is the gather's rays themselves: at A's settings one frame traces 174,080 probe rays, 32,768 cache rays and 648,000 pixel rays, the last being one per 2 by 2 block of the 1920 by 1080 internal image plus a quarter more for retracing, and the largest single pass in the atrium is evaluating the mesh surfaces those pixel rays hit, at about 1.0 ms.

For an RTX 3060 we would guess 2.5 to 3 times these figures, which would put the project's settings somewhere around 23 to 30 ms. That is an estimate from the two cards' general standing and not a measurement, and it does not meet 60 frames a second at native 1440p output. The earlier post has real 3060 numbers, but for a voxel scene at 1080p and from before later renderer changes.

If the aim is that card at 60, the cheapest lever we measured is dropping to probes only at 0.75, which saves about 3 ms on the 4090 and costs accuracy where it shows most, taking the atrium's shaded error from 3.5 to 6.5 levels. Each of the other ideas we have, such as contact shadows for the direct light or filtering normal maps to calm the cloth, is unmeasured.

14. Two Bugs the Comparison Found

Pushing one renderer through many settings in a row turned up two faults.

ℹ️
Note

TODO: at the time of writing, fixes for both of these are being worked on and neither is verified. This section describes what we saw.

The first is a render graph that rebuilds every frame. In the renderer, setting TSR quality to off also forced the render scale to 0.75. The engine sets TSR quality every frame and then sets the project's render scale. With TSR off and any scale other than 0.75, each frame therefore changed the scale twice and scheduled a rebuild. In our harness this showed up as frames taking around 7 seconds. We infer that the editor would be affected the same way at those settings, but we did not observe it there, and it is the reason variants at native resolution use TSR's native mode.

The second is worse to look at. After changing TSR or render scale while the renderer is running, hard-edged flat grey patches appear on the stone, already in the albedo, and they were still there more than 600 frames later. A fresh process with the same settings is clean. The patches look as if some surfaces lost a mask, and dirt decal meshes whose opacity mask stops being honoured would fit, but that is a guess we have not confirmed.

Albedo after switching settings liveAlbedo, fresh startAlbedo, fresh startAlbedo after switching settings live
⇆

It also nearly fooled us. Our first runs switched settings live, and their errors against the reference were two to five times those of clean runs in the atrium and corridor: 11.53, 11.03 and 10.78 levels in the atrium for P1, C and T, against 5.86, 4.52 and 4.06 once each was run in a fresh process, and about 10.5 against about 2.1 in the corridor. Every result in the sections above comes from the fresh runs.

15. Limits

There is no screen-space ambient occlusion, so occlusion finer than the gather can resolve has only the near-field term and the materials to come from. The probes have a resolution of half a metre at best and nothing relocates a buried one. One ray per pixel reads too blue and too dim in two of our views and we do not know why. The cloth stipple is unexplained. Traced reflections do not cover secondary views or glass.

On the measurement side: this is one scene from three still cameras on one GPU, with the editor open. We have no figures for camera motion, for the other Sponza level in the project, for a heavy foliage scene, where our memory safety watchdog stopped every attempt with the editor open, for voxel worlds in this round, or for an RTX 3060.

Credits

The scene is the 2022 remaster of Sponza, commissioned from Frank Meinl and sponsored by Anton Kaplanyan, with its curtains from the add-on package by Katica Putica, Cristiano Siqueira, Timothy Heath, Justin Prazen, Sebastian Herholz, Bruce Cherniak and Anton Kaplanyan, with additional reference photography credited to Katica Putica, Princino.photo, Dubrovnik. The licence file distributed with it carries the Creative Commons Attribution 4.0 International licence, and a note that the scene is for personal and educational use with limited commercial use for marketing and print purposes. The images here are our renderer's pictures of it, with the level's fog and lens effects removed where stated.

Frank Meinl and Anton Kaplanyan. Intel Sample Library, 2022. intel.com

The published ideas this renderer is built on, DDGI, ReSTIR and ReSTIR GI, SHaRC, GI-1.0 and Lumen's world radiance cache, are credited in the earlier post. The AgX tone curve is Troy Sobotka's work. The level, the renderer and the path tracer in these pictures are Pulsar and Helio.