Path tracing - Direct lighting

This topic is 2105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

In many explanations of path tracers, such as http://www.thepolygoners.com/tutorials/GIIntro/GIIntro.htm, they apply direct lighting at each intersection point of the path. So at every intersection point, they trace a ray towards a light, and sample a different direction to continue the path.

Suppose I send out a ray that bounces three times and then hits the one light in the scene. Adding direct lighting at every bounce would be the same as not doing that, but having three paths, each leading to a light. Here the first path goes from the first intersection point to the light. The second path goes from the first to the second intersection point and then to the light. The third ray goes from the first to the second to the third intersection point and then to the light.

Is my understanding correct about this direct lighting approach? Does it sum up to the same end result?

If so, does this not lead to many more "samples" hitting a light than normally would, leading to incorrect lighting?

Share on other sites
There are two ways lighting can be contributed to a point: direct (i.e. a ray can traverse from a light source to the point) and indirect (i.e. reflected off of other surfaces before reaching the point). Path tracing is designed to take both into account; the direct lighting is sampled by casting a ray towards each light source, and the indirect light contribution is accumulated by sampling paths that orient towards the rest of the scene. The distribution of indirect light samples can be controlled to give different surface effects.

Share on other sites

Yes, they are different paths, so even though you might hit a light source twice, they are counted as different light paths. Another way to think of it is that the probability of hitting a specific point in space (such as a point light source) is zero. So even though it might appear to result in the light appearing brighter because it can be potentially counted twice, the bias converges to zero as you add more samples.

The advantage of direct lighting, of course, is that it helps a lot with very small lights, as you can directly sample them instead of relying on random chance to eventually fire a ray towards it, while keeping the result physically correct. The variance reduction is rather stunning, but of course it is situational (if you have lights everywhere direct lighting might prevent you from sampling them all in a reasonable time, for instance, but if you combine both approaches you can get the best of both worlds).

Furthermore keep in mind that an area light source (like a bright sphere) can be mathematically treated as an infinite number of point light sources... and you can integrate over that distribution of point light sources in order to use direct lighting on them.

Share on other sites

This is all about the probability of each path. As with all monte carlo integration, you have to compensate the values of each sample with the probability of choosing that sample. The probability of hitting a point or directional light with a random chance is exactly 0; they're a single point on a continuous hemisphere. On the other hand, such lights act as dirac functionals; their contribution is only non-zero at a single point and infinitely large there. This, when integrating over the hemisphere, means that you can just pull them out of the integral and sum them with the approximation of the integral; the indirect lighting.

In a mathematic sense all surfaces and lights are equal (which makes sense, secondary or tertiary light sources are just as much light sources as primary ones) but when actually tracing the scene it makes sense to try to focus on the important stuff; this also leads to importance sampling of materials and multiple importance sampling of materials and lights together.

A lot of these approaches result in the exact same results - you can trace two bounces per incoming ray, for example, just keep track of your probabilities and you'll be fine as in the result will be unbiased. The vast majority of the ideas and research on the subject don't really focus on getting the result right, but reducing variance (which is visible as noise). With bidirectional path tracing using multiple importance sampling and materials that are importance sampled accurately, you can save a lot of rendering time (orders of magnitude) and get the same level of noise in your results.

Edited by powly k

Share on other sites

Thanks for the replies!

Up until now, I just picked a direction uniformly at random from a hemisphere, which may turn out to be either of indirect or direct lighting. So when I add an extra direction, which is sure to be direct lighting, and sum it up with the possibly indirect one the scene will not seem more bright? I'm not sure how that bias converges to zero as I add more samples, because at every sample I take, I also take an extra direct lighting sample?

Unless I add weights to the rays, corresponding to their probability, which would make the above seem to make some more sense to me. And I think that that is what powly k was trying to explain to me. But how do I calculate these probabilities? Projecting an area light onto the hemisphere would give me some area of the hemisphere to pick directions from, and the probability would be that area divided by the total area of the hemisphere, right? But what probability would the indirect light sample get, then? 1 - the other probability? And what when there are multiple lights, and their projected areas on the hemisphere overlap?

I'm going to try to implement it sometime this weekend, hopefully to gain some more understanding. But am I correct so far about the following?

Wherever I usually sample a direction uniformly at random, I also sample an extra ray for every light source. This sample can be directed at any point on the light source. All of the colors returned by these samples are multiplied by their weights, which correspond to the probability of taking that specific sample and therefore should sum up to 1.

Edited by Arjan B

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75