Trying to implement Monte Carlo path tracing, I've hit a snag in the light sampling procedure.
Usually, the procedure goes as follows:
I've left out a few details about how things are randomly selected, but never mind that for the moment (see e.g. "Luminaire Sampling in Distribution Ray Tracing").
The problem, as I see it, is that both the BRDF and the distribution of light in light sources are not actual functions, but rather measures.
For instance, the BRDF of a perfectly reflecting mirror is, for each incoming angle, a dirac delta "function" in the reflected direction (i.e. a measure supported on one point, with a mass of 1 at that point). Similarly, a point light (as opposed to an area light) is modelled by a dirac delta, as opposed to a density function.
It seems important to get the distinction straight, as it allows proper importance sampling. For instance, when sampling a BRDF, one could either:
Anything in between is also possible, and important, as perfect importance sampling is not going to be possible for complex BRDFs.
Now, in the case that the BRDF is actually a dirac delta, we see that it becomes extremely important to sample according to the BRDF: sampling randomly, we have to dismiss the contribution with probability 1 (because the BRDF is supported at a single point, which we have probability 0 to choose when sampling directions uniformly), but if we do hit lucky and get the reflected direction (at which the mass is), then we have to scale the contribution to be infinitely large! If we sample according to the BRDF, we always generate the reflected direction, and don't have to scale anything (and particular don't run into any infinities).
My problem is then the following: how do you "multiply" the BRDF by the contribution of the light, in the case where they are both general measures and not just functions? How does one properly "importance sample" at this step, when considering both the importance sampling of the BRDF and the distribution of lights in the scene? (The sampling procedure for the light should take into account both the light distribution and the BRDF, so to avoid infinities.)
Ideally, one would need sampling procedures that never produce infinities, infinities which should just be artifacts of bad sampling mechanisms (as in the above). So, for the subsequent four scenarios, the calculated contribution should always be finite:
Of course, ideally this would work for any measure for both the BRDF and for the lights, but it seems being able to get the above 4 cases right is where most of the work is.
If you've got a Dirac delta from a completely specular path to a point light source, you can still evaluate the total integrated contribution of the delta. (If your BRDF is not a purely specular Dirac delta, you can and probably should handle it with ordinary ray-tracing...)
Note that this "delta path" will act differently from an ordinary ray path. Specifically, the color of an ordinary ray represents luminance (units: lumens/steradian/m^2), which is invariant with respect to distance, and -- BRDF sampling aside -- is only multiplied by coefficients of reflection and transmission.
However, the color of a "delta ray" represents illuminance (units: lumens/m^2), which is not invariant with respect to distance (it falls off as 1/r^2). Also, unlike luminance, a delta path will be affected by the curvature of specular reflectors and refractors along the path.
To take into account the paraxial behavior of curved specular surfaces, you will need to evaluate the derivative of the ray source with respect to the viewing angle at the other end. This should be representable by a 2x2 Jacobian matrix, which is multiplied at each reflection by a Jacobian representing the local curvature of the surface. Your distance calculations will also modify this matrix -- e.g., consider that a perfect lens might yield an illuminance that increases with distance, as you approach the focal point. Which also suggests you will need to handle possible singularities, where caustics focus a point light source...
Because your frame buffer has finite resolution, rendering a delta should normally (outside of caustic singularities) yield a finite (though possibly quite high) brighness. For the sake of simplicity, assume that each sample contributes to exactly one pixel: the units above suggest that you must divide the illuminance of the "delta path" by the solid angle of your pixel, to make it comparable with the luminance of your ordinary rays. (Note that solid angle will vary per pixel -- for a standard camera, you must include a cos(theta)
factor)
You should be able to do something similar to terminate a purely-specular path at a non-specular surface. I would guess that the statistics of a "delta ray" might also be different from those of conventional rays; you will need to figure out exactly how they fit into your Monte Carlo framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With