So what's the clamping in Cycles integrator?

It seems I am unable to find any technical description of the clamp.

It’s great to have it I guess, but what’s it for and how does it work.
I don’t really see any difference when choosing random values for it, nor do I know when I should use it, and unless I read the code myself it seems impossible to find out what it does to the render equation.

So, anyone has some insight with a technical basis, not some guesswork?

Don’t know if this will help much but I remember reading that it is used to reduce the effect of fireflies and noise in general.

Here’s the original svn commit message.

http://lists.blender.org/pipermail/bf-blender-cvs/2012-April/044608.html

And Dingto did a example post of it’s effect, see link below:

http://dingto.org/?p=531

I saw in recent tutorial ( can’t remember which one ) that clamp is used to stop fire flys, or really bright pixels.
They said to use values below 1 ( .7/.8/.9 ) work very well for me.
If you use 1 you get a very dark render or a very white render. I think it is “clamping” how bright a pixel can be , given the lighting setup.

If I am wrong, please correct me. Want to learn cycles.

I know what it is for, but appearently no one knows what it really does or how it works.

No offence, but stuff like “use values below 1” or “value XYZ works for me” are completely useless indicators.
I want to properly use a tool, not play with values till I get a pleasing result. :slight_smile:

I’ve also noticed that clamping dramatically changes the overall brightness and contrast of a frame.

When I got fireflies I just set it to 1.3 and they usually go away. I don’t know why, but they do. And I thought values <1 darkened the image…?

And this has been discussed earlier and from that I remembered this:

It doesn’t explain anything but shows different values on the same scene, quite helpful imo.

Hope it’s helpful for you too. :slight_smile:

Well, that’s what Cycle’s 3dview rendering is for… play with values, get instant feedback. And there’s not 1 perfect value for clamping, otherwise there would be only 1 value to choose from.

From blenderwiki:

This option will clamp all samples to a maximum intensity they can contribute to the pixel, again to reduce noise at the cost of accuracy. With value 0.0 this option is disabled, lower values clamp more light away. If the image has fireflies, there will be samples that contribute very high values to pixels, and this is option provides a way to limit that. However note that as you clamp out such values, bright colors in other places where there is no noise will be lost as well. So this is a balance between reducing the noise and keeping the image from losing its intended bright colors.

Well, if DingTo doesn’t know it’s up to Zalamander. If he doesn’t know, then the question is if Brecht even knows. :wink:

Can it be as simple as it’s about the rgb value? The fireflies are superwhite, right, so how about if a pixel with a tendency to reach a value over [clamp] automatically were excluded? That kinda sounds logical. But I’m speculation out of my @$$ now… ;D

The cycles renderer works by taking several samples of pixel values and then averaging there values which means, it adds the samples up and then divides the sum by the number of samples taken. Here is an example for illustration: The scene consists of a diamond object on a reflective plane. The diamond has a glass material and the plane is a glossy material with total reflection. Behind the diamond i have placed a pointlight (image 1).



First i rendered with 10 samples (portion of resulting image is in 2). The render has one single firefly, one white pixel in the lower center as you can see. But it is not just a white pixel. I zoom in and by clicking the mouse on it in the image editor, i can read the value; it is 2368313.25 which is actually brighter than simple white.
In image 4 i rendered the scene with 1 sample only, there is no firefly; the value is instead 0.0509 just like all the other grey pixels around it. In image 5 i rendered with 2 samples, and there the firefly pops in! Here the readout says the pixel brightness is 11841566. Because i used 2 samples and cycles works by taking the average of the samples i can use my pocket calculator to estimate the value of the firefly sample:
Samples taken are
s1 = 0.0509 (i know from image 1)
s2 = ?
average = (s1 + s2) / 2 = 11841566
solving for s2 gives: s2 = (2 * 11841566) - 0.0509 = approx. 23683132
So the “bad” sample has a value of 23683132. I do not know why exactly this sample was created, may be because of some buggy math function or floating point error or something like that (especially because this value is very close to the maximum exact representable floating point number).
If i wanted my image to be correct within 1% (ie 0.01), i could just set the number of samples to 23683132/0.01, that would be enough samples that this error would be averaged out. But rendering 2.3 billion samples could take a while, especially on older computers, so what i instead did is use the clamp value; with the clamp value, any sample value greater than the clamp value would be replaced with the clamp value instead.
i wanted to render with 100 samples, but with 0.01 accuracy, so i need to clamp the value to 1 (because 1/0.01 = 100). Or if i were willing to take 1000 samples, i would set the clamp to 10 respectively. The result is in image 6 and the firefly pixel has only a value of 0.0604 (which is within the 0.01 limit of the “real” value 0.0509). Still visible but damped.
Of course this only works if you have some idea about what the maximum sample value of the whole image could be. In my case 1 works fine. But if the maximum were e.g. 10, because i had some bright lights in the scene, i could not make the clamp value less than 10 without seriously losing contrast, and i would need to take the 1000 samples with the clamp of 10 to get the same error of 0.01.