<p>First of all, a good reference for Monte Carlo path tracing in participating media is <a href="http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf">these course notes</a> from Steve Marschner.</p>

<p>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$.</p>

<p>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 <a href="https://en.wikipedia.org/wiki/Exponential_distribution">exponential distribution</a> (with rate parameter $\sigma$) for the probability of interaction as a function of distance.</p>

<p>So, to answer your questions directly:</p>

<ol>
<li><p>You <em>can</em> 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.)</p>

<p>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.</p>

<p>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.</p></li>
<li><p>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.</p></li>
<li><p>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.</p>

<p>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.</p></li>
<li><p>Try "participating media" (that is, a volumetric "medium"&mdash;plural "media"&mdash;which "participates" in light transport), and "volumetric path tracing".</p></li>
</ol>

CC BY-SA 3.0
2016-06-07T17:25:55.173Z
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)?
RichieSams
CC BY-SA 3.0
2016-06-07T17:46:09.757Z
@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.
Nathan Reed
CC BY-SA 3.0
2016-06-07T17:51:53.400Z
Ahh, that makes sense. Though, performance will suffer... No wonder everyone wants to estimate Monte-Carlo Participating media. Thanks for all the info!
RichieSams
CC BY-SA 3.0
2016-06-07T03:47:47.680Z
2016-06-07T03:54:51.840Z
2016-06-07T03:54:51.840Z
Nathan Reed
<p>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 href="https://i.sstatic.net/tOp55.jpg" rel="noreferrer"><img src="https://i.sstatic.net/tOp55.jpg" alt="Monte Carlo Volumetric Scattering"></a>
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. </p>

<p>My questions are as follows:</p>

<ol>
<li>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? 

<ul>
<li>Would this be correct?</li>
<li>Would the pdf be a linear function for isotropic materials?</li>
<li>Does this function have a name or something I can Google?</li>
</ul></li>
<li>Would Beer-Lambert still apply between scatter events?

<ul>
<li>I would think not. Since Beer-Lambert is a simplification of actual scattering calculations.</li>
<li>Then again, perhaps Beer-Lambert is a calculation at the micro scale, and path tracing is on a macro scale.</li>
</ul></li>
<li>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?</li>
<li>Lastly, what are some better Google phrases for Monte-Carlo volumetric scattering? 

<ul>
<li>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.)</li>
</ul></li>
</ol>

<pathtracing><monte-carlo><volumetric-scattering>
Full Monte-Carlo Volumetric Scattering
RichieSams
# Full Monte-Carlo Volumetric Scattering

(Asked by: username_0 on 2016-06-04)

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:
[![Monte Carlo Volumetric Scattering](https://i.sstatic.net/tOp55.jpg)](https://i.sstatic.net/tOp55.jpg)
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.)

**Tags:** pathtracing, monte-carlo, volumetric-scattering


---

## 1 answers

### Answer by username_1 on 2016-06-07. Score: 9 | Accepted answer

First of all, a good reference for Monte Carlo path tracing in participating media is [these course notes](http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf) 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](https://en.wikipedia.org/wiki/Exponential_distribution) (with rate parameter $\sigma$) for the probability of interaction as a function of distance.

So, to answer your questions directly:

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".

> **Comments:**
> **username_0**: 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)?  
> **username_1**: @username_0 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.  
> **username_0**: Ahh, that makes sense. Though, performance will suffer... No wonder everyone wants to estimate Monte-Carlo Participating media. Thanks for all the info!  

---

