ALL INTELLIGENCE
Hacker News AIT2·Tools

Ray Splitting Makes Real-Time 3D Radiance Cascades Viable

Original title: Split Radiance Cascades
58AI Score

The article explains how Ray Splitting extends Radiance Cascades global illumination to 3D scenes without prohibitive sampling cost, yielding more accurate indirect lighting. Drawing on an arXiv paper and the author's own implementation, it offers a practical engineering walkthrough with code examples.

Full Report

Contents23 sections

Implementing 3D Radiance Cascades for Global Illumination using Ray Splitting

Image 1: San Miguel with RC GI

Intro

Radiance cascades is a technique that massively improves global illumination without much extra cost or accumulation. In this article I'll go over the recent technique of Ray Splitting which allows the use of RC (Radiance cascades) in 3D without huge costs, and how to implement it.

Note that the code examples are modified for clearability, so might not fully work

Radiance Cascades

For this article I'll assume you already know the basics of RC, if not I really recommend the interactive tutorial from jason.today or the article from MAX Here is a quick recap as well.

RC Recap

The main point of RC is combining the samples/rays for our GI in a way that utilizes them most effectively. This results in a more correct output with less samples. The way of combining this relies on the penumbra hypothesis. Which states that, when you are close to a light source you need fewer rays (less angular resolution) to find the light.

Image 2: Animation showing light missing, when further

In addition when you are close to a light you need more probes (spatial resolution) to get correct shadows

Image 3: Showing how larger interpolation works out far away

To interpolate the half shadow, we need the light at both sides. Further away this spacing can be bigger to still get probes on both sides.

By merging layers ranging from (high resolution, low direction count) to (low resolution, high direction count) that correspond to an interval of the ray, we get best of both of these in the range that matters.

Probes

Problems of 3D

RC requires storing our light into a grid of probes. This becomes a problem in 3D due to the massive memory cost that introduces. since probe counts scale ^3

Image 4: Showcasing memory scaling

Even if we would only put this around the camera it would cost way too much memory to get a decent resolution. Luckily we only need probes where we need light, which is on all visible surfaces. So we need a way to only put probes on visible geometry.

Sparse probes

To only spawn probes on visible surfaces, we reconstruct world positions from the screen. We round these positions to a grid of cells.

Image 5: Cells based on world position

To store our light in these cells we need a buffer of probes. To allocate this we use a hashtable. Creating a hash for each cell allows us to quickly allocate a slot for each of these without much fighting between threads. We also store an AppendBuffer with a list of the probes we allocated, this will be used later to launch our next passes indirectly. (this somewhat goes against the use of the hashtable, but the table will be needed more later) We clear and fill this table every frame and with this we get a table of sparsely allocated probes.

We can visualize/debug our probes in a separate pass

Image 6: A random hash per probe

Cascades

With this gather pass we now have a single cascade of probes allocated. However we need multiple cascades of lowering resolution to do RC. For this we need to fill separate hashtables for each cascade, we could just re-run our shader for each cascade but that would be very innefficient. We already have our highest detail probes and there are significantly less of them than we have pixels. So instead of running over all pixels again, we can just go over all the probes we just allocated, for each of these we just halve their position to get the cascade above it. Any duplicates we get from this are handled by the hashtable. We run this bottom up for all cascades. The number of cascades we need is somewhat arbitrairy based on your scene size i'll be using 4

Image 7: Multiple cascades shown split next to eachother

Note that when visualizing your higher cascades you need to shift your positions when creating the key

Rays

From probes vs from screen

Normally to get the lighting at every probe, we shoot a set amount of rays into random directions from each probe. This however comes with quite a few issues. Ray counts become very big with good enough spatial and angular resolution. But the main problem is probe positioning, since our probes are in a grid they are not aligned with the surfaces which can cause a bunch of rays to shoot below the surface. This can cause overocclusion and light leaking, and also makes it so we cannot shoot rays in just a hemisphere.

Image 8: A probe with 2 rays overoccluded due to being inside the ground

The 2 red rays in this probe here got unfairly blocked because the probe is too far into the ground

This would cause dark splotches in our lighting. So instead we can trace the rays from reconstructed world positions and put these into the probes that are at that spot. This way rays are sent from real geometry avoiding this problem.

Image 9: Rays being sent from the view position

Here the blue rays are sent from the position gotten from the screen, then moved into the closest probe.

Splitting into intervals

However, in RC each cascade does not contain the full ray, only a interval/segment of it. Sending multiple rays for each interval at each pixel would be quite inefficient. Instead we do it the other way around, we trace the full ray and pick the interval (and thus cascade) that it would have hit in based on its hit distance. We fill the hit interval's cascade with the lighting, and then mark transparancy / that a ray traveled through them in the cascades below the hit one.

Image 10: A ray being inside a corresponding interval

The red ray hit inside the second cascade, and thus is binned into the second and first cascade.

We store this in multiple bins per probe, one for each direction. We need to lay out these directions evenly and most importantly in a way that scales so that our merging evenly combines them into lower cascades. For shooting each ray we can just pick a random direction in a hemisphere at our hit.

With this we should now have every cascade filled with its interval of light. If we display this by just averaging all bins in an output pass, we can see the rings of light this contains.

Merging

We now want to merge these intervals together so we can get our entire path of light. We do this by going through our cascades from top down.

We need to interpolate the directions and probes. Starting with directions, since our directions are evenly mapped to 4 times more in the above cascade we evenly interpolate these in our own cascade.

However we need to also keep in account the transparency in this merging. If a ray was already blocked in the direction we're merging in the lower cascade/interval we shouldn't merge it downwards.

Image 11: Showing One interval being blocked by a wall, the further interval is blocked off

Here the middle interval is blocked, so we should not merge the light from the last interval, or it will leak in front of the wall

This merges our directions from the closest probe. Instead we want to check all the above probes and blend between them. For this we need to keep in mind probe spacing, each lower cascade has 8 probes inside 1 upper probe. So we shouldnt evenly blend.

It's also important to keep in mind that our grid is sparse, meaning the 8 surrounding probes will probably not all be there. This can be resolved by only weighing and sampling the probes that actually exist. Additionally, not all our probes are of the same quality. The amount of rays a probe contains and thus how accurate it is, is based on its visibility on the screen. We should also adjust for this, giving a higher weight to probes that contain more rays.

With this we now have our full ray inside of the lowest cascade. To display this in our output shader, we have to merge the directions of the cascade into 1 value for each pixel, using the normal of the pixel to weigh the probes.

Image 12: Full light ray

LODs

Currently we have a even grid of probes, which works fine for small scenes. But our probes get very small on the screen further away. This has 2 major problems. We shoot our rays from the screen, so the number of rays in a probe is based on how many pixels it occupies on the screen. So very small probes only get one ray or maybe even less. Secondly, the number of probes we spawn explodes further away which costs a lot of memory and is expensive to merge.

By adding a form of LODs to our probes we solve both these problems, at only the cost of lower resolution lighting far away. This is very similar to cascaded shadow maps which makes naming confusing and thus we call them LODs/Levels. For each higher LOD we also halve the resolution similarly to our higher cascades although we keep the direction count the same. To do this we just halve our cell position each level. However for this we need to add a level index to our per probe key. We need to do this since our halved positions can overlap with the lower level. We can just bitshift this index after the rest of our key.

Since everything else uses the hashtable, this should automatically work with the rest of our code assuming we calculate the key in the same way.

Image 13: LODs increasing size on distance

This fixes a lot of flickering or overallocation further away, however it creates big seams where the LODs change. So we want to blend in between these seams. To do this we keep some probes of overlap, allocating probes of both levels and also binning the ray into both. Wherever we calculate our level we instead calculate the range, making sure to keep correct weights so we do not double the light at the seam.

This should result in smooth, although flickering results.

Temporal

Due to the benefits of splitting & merging with RC our single frame result is already pretty good. But since we still send random rays, there is still some flickering especially in probes that did not get many rays. We can fix this by accumulating our probes over time. This doesnt come with the drawbacks of most temporal effects. Since our probes are spatially stable, there is no smearing from bad reprojection. And since there is not a lot of noise in after a single frame there is barely any ghosting. So the only drawback is slower lighting updates.

Example of smearing using Lumen

Video 7 No smearing or much ghosting with RC

Video 8

Stable hash table

Currently we clear and allocate the hashtable every frame, so our probe index moves every frame. To temporally accumulate we want our probes to keep the same index, so that we keep the old frame's result in their spot in the buffer. One way of doing this is by adding a layer of indirection to our hashtable, instead of storing the index into our data buffer in the table we store an index into another list of indices. That way we can add a pass that re-allocates our previous frame's results with the same index as the data.

We also need to keep track of the lifetime of probes, to know which probes to reallocate or not, and resetting their lifetime if they are on screen.

The hashtable should now be stable, you can test this using the debug output code from earlier, outputting the index. Probes shouldn't change color unless they go off the screen. With stable probes temporally accumulating is easy, when going over the probes (in the merge pass or in a separate pass) we just re-add the probes accumulated light and weights with a falloff. With that you should now have clean single bounce GI.

Multi bounce

Currently light only bounces once from where we are looking. Things only start looking really good when we do multiple bounces. To achieve this we need to trace 1 extra bounce ray everywhere, from which we can get infinite bounces over time. To get one bounce, we just shoot an extra light ray from the hits of our primary ray. To do this we output our hit positions and normals in our ray generation shader, then run a second one from that spot.

Image 14: One ray is shot, afterwards another is shot from the spot

The first hit is stored, then another random ray is sent from that hit position

This gives us a single real bounce, but increasing this to more would be very expensive. Instead we can sample the probes to apply GI to this, with the temporal accumulation that gives us an extra bounce every frame. However since our probes are only allocated where we are looking, we wouldn't be able to get this bounce light from outside of the screen, since there are no probes to sample from. To resolve this we allocate a separate secondary probe cache for this, we allocate extra probes at the hit positions of our primary ray. We fill these with radiance from the bounce ray, in the same way as our primary ray. To accumulate this to multiple bounces, we sample this cache at the hits of our primary and secondary rays.

Image 15: Animation of secondary probes

In one frame we send the primary ray, which allocates a probe filled with the bounce ray. The next frame a different bounce ray hits the same secondary probe. Since it samples the cache it then also contains the previous bounce. Over frames this stacks to infinite bounces

This gives us infinite bounces, however it is limited to only the area covered by the single bounce ray, since that one allocates the secondary probes.

We can re-use almost our whole system for this secondary probe. We already have LODs over distance, by allocating the secondary probes at at least 2 LODs higher it can fit into the same hashtable/probes without conflicts. If we also add these to the active probes the merge pass will merge their cascades as well.

With that we get nice looking multi bounce GI.

Basic optimizations & improvements

For simplicity I kept out a lot of optimizations or better ways to do things. I won't go over how to fully optimize but will briefly go over the main improvements that can be done to get this running well.

Choosing directions

One big improvement in quality is choosing directions in a better way, currently we choose completely random directions. But there are multiple semi random sequences that accumulate to good results significantly quicker. By using a deposit count per probe as an index into something like the R2 sequence or blue noise, direction coverage accumulates significantly faster.

Group sharing

Apart from tracing, our merging & applying pass is the most expensive. It's sampling a lot of data across a low amount of threads. For example the bin merging can be done across threads, loading the 8 probes together and having each thread load a bin, merging them as a group.

Lowering ray count

Raytracing cost is by far the most expensive part. We can skip a percentage of pixels every frame to reduce cost significantly, although with the drawback of slower accumulation and thus more ghosting. Balancing this with probe sizes can improve the accumulation but at the cost of light resolution. This allows for a nice way of tweaking quality vs performance. It might also be worth replacing (some of) the rays with cheaper ones like screen space rays or sampling an sdf or voxel approximation of the world

Conclusions

Performance

Almost all of the cost of this goes to actual tracing. For my implemention in Unreal on my 5070 Laptop GPU in San Miguel the cost of RC is about ~2ms depending on probe sizing. Although with ~13ms on top of raytracing at 2spp (1 primary 1 bounce) and another ~2ms for depositing the rays.

The expensive tracing cost is very variable, depending on scene size and tracing performance in general.

Comparisons/Showcase

The main points of error are light leaking in spots smaller than a (secondary) probe, and softer shadows. (presumably due to not enough base directions)

Video 9

References

"Split Radiance Cascades: Real-Time Global Illumination via Sparse Radiance Probes": https://arxiv.org/abs/2607.20384

Jason Mcghee's article: https://jason.today/rc