120448 wrote:I have a question about the energy redistribution regarding importance sampling. As you no longer scale the energy with N dot L, the energy of all the rays will never be below 1. It would only increase due to Russian Roulette and this causes very bright spot in corners where the rays bounce a lot. My question is, what factors are affecting the energy after each bounce?
After each bounce, you still scale by N dot L. However, when using IS, you also scale by 1/PDF, or in English, the probability of selecting a direction. Since the PDF is proportional to N dot L, these cancel out, and ray energy is left unmodified, except for the 'normalization factor' for the PDF: Integrating N dot L yields a surface of PI, so you need to divide by PI.
Obviously this is only true for diffuse bounces; for specular bounces things get more tricky. It gets worse when the BRDF is a blend of diffuse and specular, or a blend of pure specular (mirror) and diffuse and so on. In that case, you may want to actually perform both steps: scale by N dot L, divide by PDF, to make sure everything remains correct. That's what I do in Arauna2.
Scaling also happens for explicit light rays (direct connections to the light source); in that case, you need to calculate the probability of hitting the light source using a random ray. This is proportional to the dot between the light surface normal and the light ray, scaled by N dot L, and scaled by 1/r^2.
Russian roulette is also a form of IS, and therefore rays that are not terminated are scaled by 1/P, where P is the survival probability. IS is everywhere.
Due to all this scaling, some paths can transfer a lot of energy, but this compensates for all the paths that are not generated and directions that are seldomly considered. Especially long paths can transfer a lot of energy, and when these paths stumble upon a light source, you get bright spots ('fireflies'). There's not much you can do about that, but if you loosen the requirements in terms of mathematical correctness, you have some options:
1. Filter the final image: any pixel that deviates too much from it's neighbors in terms of brightness is toned down;
2. (better:) Clamp max path transport: any path that brings back more than a certain amount of energy is toned down. This is what VRay3 does, and Arauna2 also uses this trick. Arauna2 has a slider that lets you specify the clamp value. A low clamp value tends to kill caustics, but a high clamp value results in fireflies.
So you're doing nothing wrong, and fireflies are a normal result... Ultimately they should go away, but if you can't wait, try the clamp.
It gets really beautiful when you start doing 'multiple importance sampling' by the way, but the theory is hairy. One example for direct light connections: a direct light connection could theoretically be achieved in two ways. One is the direct connection (PDF is N dot L times NL dot L times 1/r^2); the other is through a regular bounce, by evaluating the BRDF. For small distant lights, option 1 is the best, since a bounce is unlikely to hit the light. However, for large nearby lights, sometimes option 2 is better. For a single direction L, you can evaluate both, and then combine them using the power heuristic, yielding an optimal blend between the two. This greatly helps for wall sections near a large ceiling light. You can take MIS to extremes using bidirectional path tracing, where paths from the light and to the light are combined using the power heuristic to always use the optimal PDF. But that's really something for another course.
- Jacco.