# Full Monte-Carlo Volumetric Scattering

I would like to add full monte-carlo volumetric scattering to my path tracer, but I'm having a hard time researching how to do it. Let me explain what I would like to do: A ray enters a material, and we apply the BTDF, then after some distance, a volumetric scattering event happens, after which (in the isotropic case), the ray scatters in any direction in the sphere. This repeats until the ray exits the material with another BTDF.

My questions are as follows:

1. How do I choose the distance between scatter events? Intuition tells me there should be some kind of scatter pdf, which gives the probability to scatter after a certain distance?
• Would this be correct?
• Would the pdf be a linear function for isotropic materials?
• Does this function have a name or something I can Google?
2. Would Beer-Lambert still apply between scatter events?
• I would think not. Since Beer-Lambert is a simplification of actual scattering calculations.
• Then again, perhaps Beer-Lambert is a calculation at the micro scale, and path tracing is on a macro scale.
3. What is the volumetric equivalent to a BSDF? It looks like I can use a phase function such as Henyey-Greenstein to determine the new direction, but what do I use for attenuation?
4. Lastly, what are some better Google phrases for Monte-Carlo volumetric scattering?
• Searching volumetric scattering, or SSS, ends up giving papers, methods, and blog posts about the simplfications of full Monte-Carlo simulation (Dipole, in-scattering, out-scattering, diffusion, etc.)

First of all, a good reference for Monte Carlo path tracing in participating media is these course notes from Steve Marschner.

The way I like to think about volume scattering is that a photon traveling through a medium has a certain probability per unit length of interacting (getting scattered or absorbed). As long as it doesn't interact, it just goes in a straight line unimpeded and without losing energy. The greater the distance, the greater the probability that it interacts somewhere in that distance. The interaction probability per unit length is the coefficient $\sigma$ that you see in the equations. We usually have separate coefficients for scattering and absorption probabilities, so $\sigma = \sigma_s + \sigma_a$.

This probability per unit length is exactly the origin of the Beer-Lambert law. Slice a ray segment into infinitesimal intervals, treat each interval as an independent possible place to interact, then integrate along the ray; you get an exponential distribution (with rate parameter $\sigma$) for the probability of interaction as a function of distance.

1. You can technically choose the distance between events however you want, as long as you correctly weight the path for the probability that a photon can make it between two adjacent events without interacting with the medium. In other words, each path segment within the medium contributes a weight factor of $e^{-\sigma x}$, where $x$ is the length of the segment. (This is assuming a homogeneous medium, but see section 4.2 in the Marschner notes linked above for what to do if it's inhomogeneous.)

Given this, a usually good choice for the distance is to importance-sample it from the exponential distribution. In other words, you set $x = -(\ln \xi)/\sigma$ and then leave out the $e^{-\sigma x}$ factor from the path weight.

Then, to account for absorption, you can use Russian roulette to kill off a fraction $\sigma_a/\sigma$ of the paths at each event. This is particularly necessary for very large or infinite media (think atmospheric scattering) where the path could bounce around for an arbitrarily long time if it's not killed. If you're only dealing with small and not-too-dense media, then it might be better to just factor in a weight of $1 - \sigma_a/\sigma$ per event, rather than using Russian roulette.

2. No, if you follow the importance-sampling procedure just described, Beer-Lambert is already incorporated implicitly in the sampling, so you don't want to apply it to the path weights.

3. The volumetric equivalent to a BSDF is the combination of the scattering and absorption coefficients $\sigma_s, \sigma_a$ and the phase function. By convention, the coefficients control the overall balance of transmission, scattering, and absorption, while the phase function is always normalized.

You could do something like this for BSDFs too; you could factor out the overall albedo, and have the directional dependence always be normalized. It's mostly a matter of convention AFAICT.

4. Try "participating media" (that is, a volumetric "medium"—plural "media"—which "participates" in light transport), and "volumetric path tracing".

• How would you sample distances for non-monochromatic scattering/absorption coefficients? Randomly choose a channel, then divide by 1/3 (in the case of RGB or XYZ)? Jun 7 '16 at 17:25
• @RichieSams The recommendation I've seen for that case is to assign each ray a single wavelength or color channel. So you basically calculate the scattering for each channel separately. For instance, in atmospheric scattering, blue light scatters much more strongly than red and therefore needs a lot more scattering events, and the blue photons will follow much more convoluted paths than the red ones. So it makes some sense to simulate them separately—much like dispersion due to refraction. I've never really tried this myself though. Jun 7 '16 at 17:46
• Ahh, that makes sense. Though, performance will suffer... No wonder everyone wants to estimate Monte-Carlo Participating media. Thanks for all the info! Jun 7 '16 at 17:51