Secondary ray clamping

Last updated 2019/01/04

The concept

"Secondary ray clamping" is also known as "maximum ray intensity", "maximum sample intensity", and probably many other variants. The idea, however, is always the same. You want to limit the intensity of the value that the ray returns. So instead of having a global illumination sample that returns a value of 237.25 you want to limit it to, for example, 20.0. No secondary sample is allowed to exceed this value and will be clamped if it does.

Why would you want to clamp anything?

Clamping doesn't sound like something you would want to do to achieve a photorealistic rendering... and this is true to some extent. However, clamping at the right place at a sensible level can make a tremendous difference in render times and noise level without affecting the overall image noticeably. Let's get straight to a real-world example.

No secondary ray clamping

A typical interior room with a physical sun and sky system for illumination. We can see a lot of noise pretty much everywhere except for the wall with the window. We might assume that the portal light in the window is somehow responsible for this problem but the noise is only present in the global illumination pass so there must be something else happening.

strip of light in the window

If we decrease the display exposure, we can see that there is a small strip of light in our window. The sunlight angle is very high and almost parallel to the wall, so we only get a small amount of direct sunlight. The intensity of the pixels in this small sunlit area is huge. We get RGB values easily exceeding 100.0 (in float).
So what happens is that those global illumination samples very rarely hit that small strip of intense light at the window and return values way beyond a sensible level. The chance of hitting that tiny area is so minuscule that only a very small fraction of all the samples on all the pixels will even hit it. This leads to very coarse noise that takes an unreasonable amount of time to get rid of. Note that this one very intense sample could be averaged with 100 other black samples and still be over 1.0 (meaning it would still be white in the render). That's why this type of noise is very persistent and why it is not reasonable to try to solve it by just sampling more and more. The solution to this problem is clamping the most intense samples to a lower level.

secondary ray clamping at 20.0

The same render as before just with a clamped secondary samples intensity at 20.0. We can see that the noise level has decreased dramatically. The render times also went down and the overall look is mostly the same. We lose a bit of the warm sunlight but it's usually very hard to tell in a more realistic and complex scene.
Most render engines clamp the secondaries to a level between 10.0 and 20.0, some even as low as 4.0. The difference is usually not perceptible in exterior scenes and a matter of efficiency in interiors. Artists who are rendering high-quality interior still images may prefer to increase the level a bit whereas animations profit immensely from a lower clamp level.

Note that the secondary samples clamping also affects other ray types, not just global illumination!
Be aware that there is an important difference between clamping primary rays versus clamping secondary rays. Make sure you are actually only clamping the secondary rays.