|
1340 | 1340 | in the _LMS color space_ (long, medium, short).
|
1341 | 1341 |
|
1342 | 1342 | If the light does scatter, it will have a directional distribution that we can describe as a PDF
|
1343 |
| -over solid angle. I will refer to this as its _scattering PDF_: $\mathit{pScatter}()$. The scattering PDF |
1344 |
| -will vary with the outgoing direction: $\mathit{pScatter}(\omega_o)$. The scattering PDF can also vary with |
1345 |
| -_incident direction_: $\mathit{pScatter}(\omega_i, \omega_o)$. You can see this varying with incident |
1346 |
| -direction when you look at reflections off a road -- they become mirror-like as your viewing angle |
1347 |
| -(incident angle) approaches grazing. Lastly, the scattering PDF can also depend on the scattering |
1348 |
| -position: $\mathit{pScatter}(\textbf{x}, \omega_i, \omega_o)$. The $\textbf{x}$ is just a vector representing |
1349 |
| -the scattering position: $\textbf{x} = (x, y, z)$. The Albedo of an object can also depend on these |
1350 |
| -quantities: $A(\textbf{x}, \omega_i, \omega_o)$. |
| 1343 | +over solid angle. I will refer to this as its _scattering PDF_: $\mathit{pScatter}()$. The |
| 1344 | +scattering PDF will vary with the outgoing direction: $\mathit{pScatter}(\omega_o)$. The scattering |
| 1345 | +PDF can also vary with _incident direction_: $\mathit{pScatter}(\omega_i, \omega_o)$. You can see |
| 1346 | +this varying with incident direction when you look at reflections off a road -- they become |
| 1347 | +mirror-like as your viewing angle (incident angle) approaches grazing. Lastly, the scattering PDF |
| 1348 | +can also depend on the scattering position: $\mathit{pScatter}(\textbf{x}, \omega_i, \omega_o)$. The |
| 1349 | +$\textbf{x}$ is just a vector representing the scattering position: $\textbf{x} = (x, y, z)$. The |
| 1350 | +Albedo of an object can also depend on these quantities: $A(\textbf{x}, \omega_i, \omega_o)$. |
1351 | 1351 |
|
1352 | 1352 | <div class='together'>
|
1353 | 1353 | The color of a surface is found by integrating these terms over the unit hemisphere by the incident
|
|
1363 | 1363 | that is shining on that point. This is a recursive algorithm, and is the reason our `ray_color`
|
1364 | 1364 | function returns the color of the current object multiplied by the color of the next ray.
|
1365 | 1365 |
|
1366 |
| -Note that $A()$, $\mathit{pScatter}()$, and $\text{Color}_i()$ may all depend on the wavelength of the light, |
1367 |
| -$\lambda$, but I've left it out of the equation because it's complicated enough as it is. |
| 1366 | +Note that $A()$, $\mathit{pScatter}()$, and $\text{Color}_i()$ may all depend on the wavelength of |
| 1367 | +the light, $\lambda$, but I've left it out of the equation because it's complicated enough as it is. |
1368 | 1368 | </div>
|
1369 | 1369 |
|
1370 | 1370 |
|
|
1385 | 1385 | For a Lambertian surface we already implicitly implemented this formula for the special case where
|
1386 | 1386 | $p()$ is a cosine density. The $\mathit{pScatter}()$ of a Lambertian surface is proportional to
|
1387 | 1387 | $\cos(\theta_o)$, where $\theta_o$ is the angle relative to the surface normal. All two dimensional
|
1388 |
| -PDFs need to integrate to one over the whole surface (remember that $\mathit{pScatter}()$ is a PDF). We set |
1389 |
| -$\mathit{pScatter}(\theta_o < 0) = 0$ so that we don't scatter below the horizon. The integral of |
1390 |
| -$\cos(\theta_o)$ over the hemisphere is $\pi$. |
| 1388 | +PDFs need to integrate to one over the whole surface (remember that $\mathit{pScatter}()$ is a |
| 1389 | +PDF). We set $\mathit{pScatter}(\theta_o < 0) = 0$ so that we don't scatter below the horizon. The |
| 1390 | +integral of $\cos(\theta_o)$ over the hemisphere is $\pi$. |
1391 | 1391 |
|
1392 | 1392 | <div class='together'>
|
1393 | 1393 | To integrate over the hemisphere, remember that in spherical coordinates:
|
|
1446 | 1446 | <div class='together'>
|
1447 | 1447 | Our goal over the next two chapters is to instrument our program to send a bunch of extra rays
|
1448 | 1448 | toward light sources so that our picture is less noisy. Let’s assume we can send a bunch of rays
|
1449 |
| -toward the light source using a PDF $\mathit{pLight}(\omega_o)$. Let’s also assume we have a PDF related to |
1450 |
| -$\mathit{pScatter}$, and let’s call that $\mathit{pSurface}(\omega_o)$. A great thing about PDFs is that you can just |
1451 |
| -use linear mixtures of them to form mixture densities that are also PDFs. For example, the simplest |
1452 |
| -would be: |
| 1449 | +toward the light source using a PDF $\mathit{pLight}(\omega_o)$. Let’s also assume we have a PDF |
| 1450 | +related to $\mathit{pScatter}$, and let’s call that $\mathit{pSurface}(\omega_o)$. A great thing |
| 1451 | +about PDFs is that you can just use linear mixtures of them to form mixture densities that are also |
| 1452 | +PDFs. For example, the simplest would be: |
1453 | 1453 |
|
1454 |
| - $$ p(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} \mathit{pLight}(\omega_o)$$ |
| 1454 | + $$ p(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} |
| 1455 | + \mathit{pLight}(\omega_o)$$ |
1455 | 1456 | </div>
|
1456 | 1457 |
|
1457 | 1458 | As long as the weights are positive and add up to one, any such mixture of PDFs is a PDF. Remember,
|
1458 | 1459 | we can use any PDF: _all PDFs eventually converge to the correct answer_. So, the game is to figure
|
1459 | 1460 | out how to make the PDF larger where the product
|
1460 | 1461 |
|
1461 |
| - $$ \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot \text{Color}_i(\textbf{x}, \omega_i) $$ |
| 1462 | + $$ \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot |
| 1463 | + \text{Color}_i(\textbf{x}, \omega_i) $$ |
1462 | 1464 |
|
1463 | 1465 | is largest. For diffuse surfaces, this is mainly a matter of guessing where
|
1464 | 1466 | $\text{Color}_i(\textbf{x}, \omega_i)$ is largest. Which is equivalent to guessing where the most
|
1465 | 1467 | light is coming from.
|
1466 | 1468 |
|
1467 |
| -For a mirror, $\mathit{pScatter}()$ is huge only near one direction, so $\mathit{pScatter}()$ matters a lot more. In |
1468 |
| -fact, most renderers just make mirrors a special case, and make the $\mathit{pScatter}()/p()$ implicit -- our |
1469 |
| -code currently does that. |
| 1469 | +For a mirror, $\mathit{pScatter}()$ is huge only near one direction, so $\mathit{pScatter}()$ |
| 1470 | +matters a lot more. In fact, most renderers just make mirrors a special case, and make the |
| 1471 | +$\mathit{pScatter}()/p()$ implicit -- our code currently does that. |
1470 | 1472 |
|
1471 | 1473 |
|
1472 | 1474 | Returning to the Cornell Box
|
|
2416 | 2418 | </div>
|
2417 | 2419 |
|
2418 | 2420 | <div class='together'>
|
2419 |
| -The details of how this is done under the hood varies for $\mathit{pSurface}$ and $\mathit{pLight}$, but that is |
2420 |
| -exactly what class hierarchies were invented for! It’s never obvious what goes in an abstract class, |
2421 |
| -so my approach is to be greedy and hope a minimal interface works, and for `pdf` this implies: |
| 2421 | +The details of how this is done under the hood varies for $\mathit{pSurface}$ and $\mathit{pLight}$, |
| 2422 | +but that is exactly what class hierarchies were invented for! It’s never obvious what goes in an |
| 2423 | +abstract class, so my approach is to be greedy and hope a minimal interface works, and for `pdf` |
| 2424 | +this implies: |
2422 | 2425 |
|
2423 | 2426 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2424 | 2427 | #ifndef PDF_H
|
|
2741 | 2744 |
|
2742 | 2745 | For example, we could just average the two densities:
|
2743 | 2746 |
|
2744 |
| - $$ \mathit{pMixture}(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} \mathit{pLight}(\omega_o)$$ |
| 2747 | + $$ \mathit{pMixture}(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} |
| 2748 | + \mathit{pLight}(\omega_o)$$ |
2745 | 2749 |
|
2746 | 2750 | <div class='together'>
|
2747 | 2751 | How would we instrument our code to do that? There is a very important detail that makes this not
|
|
2769 | 2773 | correct, we would have to solve backwards to figure which PDF the direction could come from. Which
|
2770 | 2774 | honestly sounds like a nightmare, but fortunately we don't need to do that. There are some
|
2771 | 2775 | directions that both PDFs could have generated. For example, a direction toward the light could have
|
2772 |
| -been generated by either $\mathit{pLight}$ _or_ $\mathit{pSurface}$. It is sufficient for us to solve for the pdf |
2773 |
| -value of $\mathit{pSurface}$ and of $\mathit{pLight}$ for a random direction and then take the PDF mixture weights to |
2774 |
| -solve for the total PDF value for that direction. The mixture density class is actually pretty |
2775 |
| -straightforward: |
| 2776 | +been generated by either $\mathit{pLight}$ _or_ $\mathit{pSurface}$. It is sufficient for us to |
| 2777 | +solve for the pdf value of $\mathit{pSurface}$ and of $\mathit{pLight}$ for a random direction and |
| 2778 | +then take the PDF mixture weights to solve for the total PDF value for that direction. The mixture |
| 2779 | +density class is actually pretty straightforward: |
2776 | 2780 |
|
2777 | 2781 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2778 | 2782 | class mixture_pdf : public pdf {
|
|
0 commit comments