TU Wien Rendering #24 - Importance Sampling

Importance sampling reduces noise in rendering by matching your sample distribution to the integrand. Instead of uniform sampling, use cosine-weighted hemisphere sampling to cancel out the cosine and pi factors in the rendering equation and get cleaner results with fewer samples.
Chapters
Let's talk about important sampling, because we have always been talking about uniform distribution. You will see that it's not usually it's not a really great idea to sample any function with a uniform distribution. And what I am usually looking for is that I have a function that I would like to reconstruct and I have a fixed sample budget. And from this budget, like X samples or X samples per pixel, I would like to get the best estimation possible. Now we have written the formula for important sampling. This important sampling was before, when I divided by the P of X, because I don't only have the F, I also take into consideration the P. And there I can plug in an or different sample. It can be uniform distribution, it can be a Gaussian distribution, it can be many things. Now take a look at this. Okay, so I would like to integrate this function, which is the blue line. So it's a spiky function. And imagine that the green bars is the actual sampling distribution that I use. It doesn't look like a good idea. Can anyone have a mean bar? Because the green bars are too high in the right side. Exactly. That's true. So the green bars are too low, too high on the right side and too low in the middle. Why is this a problem? Just a bit louder. It's not representing the actual distribution exactly. So it has to represent the actual distribution that we would like to sample. Why? Well, let's skip a few slides. Okay, so if the function takes a higher value at some regions, this means that if I miss out on the reconstruction of this region, then my error is going to be high. So what you could say is that if there is like a Gaussian function or a spiky function, I would want to put more samples where the spike is, because that's a large area. So if I can reconstruct this large area better, I'm doing much better. As if I would be sampling the parts that actually have very small intervals. So the flat regions that are almost zero. So let's put more samples to the regions where the function is actually larger. And if we do this correctly, then what we're doing is called important sampling. So what we're looking for is that I have these green bars and these green bars should match the blue function. Important sampling. Again, I am looking for the expected value of F over P. So I divided and multiplied with P in the expected value formula. And the question is, what should be the P that I plan in here? So this can be the uniform distribution on ab, or it can be an arbitrary distribution, what would be a good distribution? Usually what is proportional to the function. So if the function is large somewhere, the sampling distribution has to sample that region often. So it also should be large. If it's small in different regions, then it also should be small. And this also says that if there are regions where the function is zero, I don't want to put samples there at all, because there's nothing to reconstruct the curve below the function is zero. And we will deal with constructing functions like that. But for now, imagine that I have in my hand a function that is representative of the integral. Now we have talked a bit about this, so this should give me quite a bit of an advantage because. Because otherwise it's not worth anything. So this is a rendered image with no important sampling. And look closely, you will see now results with importance sampling. So fixed sample budget, it was running for the same amount of time. And this is the difference that you can obtain with simple importance. So this means wherever there is more light, I will put more samples, and the darker regions I will neglect to be. Let's take a look at another example. We can see how this, how noisy this region is next to the car. And with the important sampling this is accounted for much better. Now we are finally at the moment where we can attempt to solve the rendering equation. So this infinite dimensional singular, this problem child that, that is so difficult that it seems at first that no one should ever blow up water to even try it. But now it seems that we have every tool in order to solve it. So just again, the intuition, the left side after the equality sign means that there are objects that emit light, light sources, if you will. And this I have to account for. But this is not the only source of light. As these objects emit light, then these will hit other objects that reflect this amount of light. So this means that I emit an amount of light and I also reflect an amount of incoming light, taking into consideration also light attenuation and the vrdf, which is the material properties of the object that I have at hand. So let's evaluate this through Monte Carlo integration. So again, the formula, I am sampling F P. This is equivalent of integrating F from A to B. Now what is F? F is what you see up here on the right, this whole thing, sorry, just the integral part and P will be something. So I just substitute the very same thing in here on the right side. So incoming light times the BRDF times the light attenuation factor and there is going to be a P, which is now A sampling probability for outgoing direction. So this means that I hit an object and I need to have a choice. Which outgoing direction should I sample, where should I continue, in which direction? In my rectangular. So this is going to be one direction of the hemisphere. This is the Monte Carlo estimator for the actual integral. And let's imagine that we are trying to solve this for a diffuse object. So a diffuse BRDF is rho over PI. Normally it was one over PI. Why? How can a BRDF be just a number? Well, easy. A perfect diffuse material means that all possible output interactions have the same probability. If I hit this table, if it would be perfectly diffused, we talked about the fact that this is actually glossy, that if it would be perfectly diffused, like the most I have here, I hit it somewhere. And the outgoing direction can be anywhere on this illumination hemisphere. They all have the same probability. What does Rho mean? Rho is the albedo of the material. Because if I say one over PI, this means that every ray that comes in will have an outgoing radius. So this object would be competing reflective. It wouldn't absorb completely white, it wouldn't absorb any of the rings. Most objects are not like that. So this absorption is wavelength dependent and we can represent this as rho. Now how does the equation look like? I just substituted rho PI for the vrdf. So it seems that we know everything in this one, just the incoming gradients. So what do we do with this sampling distribution when we hit this diffuse object? We send out samples and we try to collect the incoming radiance, which is the Li with this sampling distribution. And the question is, for this case, what would be a good sampling probability that it function to sample the diffuse here? Now what we said is that this P, the denominator should be proportional to the numerator. Now Li we don't know. This is some part that we cannot really estimate. Because I would have to send many samples out on this hemisphere to know exactly how much light is coming in. But by the time I get to know how much light is coming in, I've done the sampling. So then I am not interested in the sampling distribution because I have a converted image. So this part we will leave out from the important sampling. This we cannot handle as of now. But this rho over PI times cosine of theta we can deal with. So let's imagine this sampling distribution which is cosine of theta over PI. And the goal of this is that these people will kill each other. I have a cosine theta in the numerator and the denominator and the same with PI. So this only. So only this part will remain there. I could technically also put the albedo of this given material in the sampling distribution. But let's be general for now. So in the end, I have this simple equation. Look at this. This is what is going to be the solution of this infinite dimensional integral. What it says is that I'm going to send samples on this hemisphere and I'm going to average it. Because in the end I define by. That's it. And then if you do something like this and you add the volumetric part, then you can render margarine Tyrell from the Game of Thrones.










