|
388 | 388 | Our Buffon Needle example is a way of calculating $\pi$ by solving for the ratio of the area of the
|
389 | 389 | circle and the area of the inscribing square:
|
390 | 390 |
|
391 |
| - $$ \frac{\text{area}(\textit{circle})}{\text{area}(\textit{square})} = \frac{\pi}{4} $$ |
| 391 | + $$ \frac{\text{area}(\mathit{circle})}{\text{area}(\mathit{square})} = \frac{\pi}{4} $$ |
392 | 392 |
|
393 | 393 | We picked a bunch of random points in the inscribing square and counted the fraction of them that
|
394 | 394 | were also in the unit circle. This fraction was an estimate that tended toward $\frac{\pi}{4}$ as
|
|
397 | 397 | $\frac{\pi}{4}$, and we know that the area of a inscribing square is $4r^2$, so we could then use
|
398 | 398 | those two quanties to get the area of a circle:
|
399 | 399 |
|
400 |
| - $$ \frac{\text{area}(\textit{circle})}{\text{area}(\textit{square})} = \frac{\pi}{4} $$ |
401 |
| - $$ \frac{\text{area}(\textit{circle})}{(2r)^2} = \frac{\pi}{4} $$ |
402 |
| - $$ \text{area}(\textit{circle}) = \frac{\pi}{4} 4r^2 $$ |
403 |
| - $$ \text{area}(\textit{circle}) = \pi r^2 $$ |
| 400 | + $$ \frac{\text{area}(\mathit{circle})}{\text{area}(\mathit{square})} = \frac{\pi}{4} $$ |
| 401 | + $$ \frac{\text{area}(\mathit{circle})}{(2r)^2} = \frac{\pi}{4} $$ |
| 402 | + $$ \text{area}(\mathit{circle}) = \frac{\pi}{4} 4r^2 $$ |
| 403 | + $$ \text{area}(\mathit{circle}) = \pi r^2 $$ |
404 | 404 |
|
405 | 405 | We choose a circle with radius $r = 1$ and get:
|
406 | 406 |
|
407 |
| - $$ \text{area}(\textit{circle}) = \pi $$ |
| 407 | + $$ \text{area}(\mathit{circle}) = \pi $$ |
408 | 408 |
|
409 | 409 | Our work above is equally valid as a means to solve for $pi$ as it is a means to solve for the area
|
410 | 410 | of a circle:
|
|
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_: $\textit{pScatter}()$. The scattering PDF |
1344 |
| -will vary with the outgoing direction: $\textit{pScatter}(\omega_o)$. The scattering PDF can also vary with |
1345 |
| -_incident direction_: $\textit{pScatter}(\omega_i, \omega_o)$. You can see this varying with incident |
| 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 | 1346 | direction when you look at reflections off a road -- they become mirror-like as your viewing angle
|
1347 | 1347 | (incident angle) approaches grazing. Lastly, the scattering PDF can also depend on the scattering
|
1348 |
| -position: $\textit{pScatter}(\textbf{x}, \omega_i, \omega_o)$. The $\textbf{x}$ is just a vector representing |
| 1348 | +position: $\mathit{pScatter}(\textbf{x}, \omega_i, \omega_o)$. The $\textbf{x}$ is just a vector representing |
1349 | 1349 | the scattering position: $\textbf{x} = (x, y, z)$. The Albedo of an object can also depend on these
|
1350 | 1350 | quantities: $A(\textbf{x}, \omega_i, \omega_o)$.
|
1351 | 1351 |
|
|
1355 | 1355 |
|
1356 | 1356 | $$ \text{Color}_o(\textbf{x}, \omega_o) = \int_{\omega_i}
|
1357 | 1357 | A(\textbf{x}, \omega_i, \omega_o) \cdot
|
1358 |
| - \textit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot |
| 1358 | + \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot |
1359 | 1359 | \text{Color}_i(\textbf{x}, \omega_i) $$
|
1360 | 1360 |
|
1361 | 1361 | We've added a $\text{Color}_i$ term. The scattering PDF and the albedo at the surface of an object
|
1362 | 1362 | are acting as filters to the light that is shining on that point. So we need to solve for the light
|
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()$, $\textit{pScatter}()$, and $\text{Color}_i()$ may all depend on the wavelength of the light, |
| 1366 | +Note that $A()$, $\mathit{pScatter}()$, and $\text{Color}_i()$ may all depend on the wavelength of the light, |
1367 | 1367 | $\lambda$, but I've left it out of the equation because it's complicated enough as it is.
|
1368 | 1368 | </div>
|
1369 | 1369 |
|
|
1374 | 1374 | If we apply the Monte Carlo basic formula we get the following statistical estimate:
|
1375 | 1375 |
|
1376 | 1376 | $$ \text{Color}_o = \frac{A(\textbf{x}, \omega_i, \omega_o) \cdot
|
1377 |
| - \textit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot |
| 1377 | + \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot |
1378 | 1378 | \text{Color}_i(\textbf{x}, \omega_i)}
|
1379 | 1379 | {p(\textbf{x}, \omega_o)} $$
|
1380 | 1380 |
|
|
1383 | 1383 | </div>
|
1384 | 1384 |
|
1385 | 1385 | For a Lambertian surface we already implicitly implemented this formula for the special case where
|
1386 |
| -$p()$ is a cosine density. The $\textit{pScatter}()$ of a Lambertian surface is proportional to |
| 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 $\textit{pScatter}()$ is a PDF). We set |
1389 |
| -$\textit{pScatter}(\theta_o < 0) = 0$ so that we don't scatter below the horizon. The integral of |
| 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 | 1390 | $\cos(\theta_o)$ over the hemisphere is $\pi$.
|
1391 | 1391 |
|
1392 | 1392 | <div class='together'>
|
|
1404 | 1404 | If we have a scattering PDF that is $\cos(\theta_o)$ over the hemisphere, then we need to normalize
|
1405 | 1405 | by $\pi$. So for a Lambertian surface the scattering PDF is:
|
1406 | 1406 |
|
1407 |
| - $$ \textit{pScatter}(\omega_o) = \frac{\cos(\theta_o)}{\pi} $$ |
| 1407 | + $$ \mathit{pScatter}(\omega_o) = \frac{\cos(\theta_o)}{\pi} $$ |
1408 | 1408 | </div>
|
1409 | 1409 |
|
1410 | 1410 | <div class='together'>
|
1411 | 1411 | We'll assume that the PDF is equal to the scattering PDF:
|
1412 | 1412 |
|
1413 |
| - $$ p(\omega_o) = \textit{pScatter}() = \frac{\cos(\theta_o)}{\pi} $$ |
| 1413 | + $$ p(\omega_o) = \mathit{pScatter}() = \frac{\cos(\theta_o)}{\pi} $$ |
1414 | 1414 |
|
1415 | 1415 | The numerator and denominator cancel out, and we get:
|
1416 | 1416 |
|
|
1428 | 1428 | _Bidirectional Reflectance Distribution Function_ (BRDF). It relates pretty simply to our terms:
|
1429 | 1429 |
|
1430 | 1430 | $$ BRDF(\omega_i, \omega_o) = \frac{A(\textbf{x}, \omega_i, \omega_o) \cdot
|
1431 |
| - \textit{pScatter}(\textbf{x}, \omega_i, \omega_o)}{\cos(\theta_o)} $$ |
| 1431 | + \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o)}{\cos(\theta_o)} $$ |
1432 | 1432 |
|
1433 | 1433 | So for a Lambertian surface for example, $BRDF = A / \pi$. Translation between our terms and BRDF is
|
1434 | 1434 | easy. For participating media (volumes), our albedo is usually called the _scattering albedo_, and
|
|
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 $\textit{pLight}(\omega_o)$. Let’s also assume we have a PDF related to |
1450 |
| -$\textit{pScatter}$, and let’s call that $\textit{pSurface}(\omega_o)$. A great thing about PDFs is that you can just |
| 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 | 1451 | use linear mixtures of them to form mixture densities that are also PDFs. For example, the simplest
|
1452 | 1452 | would be:
|
1453 | 1453 |
|
1454 |
| - $$ p(\omega_o) = \frac{1}{2} \textit{pSurface}(\omega_o) + \frac{1}{2} \textit{pLight}(\omega_o)$$ |
| 1454 | + $$ p(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} \mathit{pLight}(\omega_o)$$ |
1455 | 1455 | </div>
|
1456 | 1456 |
|
1457 | 1457 | As long as the weights are positive and add up to one, any such mixture of PDFs is a PDF. Remember,
|
1458 | 1458 | we can use any PDF: _all PDFs eventually converge to the correct answer_. So, the game is to figure
|
1459 | 1459 | out how to make the PDF larger where the product
|
1460 | 1460 |
|
1461 |
| - $$ \textit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot \text{Color}_i(\textbf{x}, \omega_i) $$ |
| 1461 | + $$ \mathit{pScatter}(\textbf{x}, \omega_i, \omega_o) \cdot \text{Color}_i(\textbf{x}, \omega_i) $$ |
1462 | 1462 |
|
1463 | 1463 | is largest. For diffuse surfaces, this is mainly a matter of guessing where
|
1464 | 1464 | $\text{Color}_i(\textbf{x}, \omega_i)$ is largest. Which is equivalent to guessing where the most
|
1465 | 1465 | light is coming from.
|
1466 | 1466 |
|
1467 |
| -For a mirror, $\textit{pScatter}()$ is huge only near one direction, so $\textit{pScatter}()$ matters a lot more. In |
1468 |
| -fact, most renderers just make mirrors a special case, and make the $\textit{pScatter}()/p()$ implicit -- our |
| 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 | 1469 | code currently does that.
|
1470 | 1470 |
|
1471 | 1471 |
|
|
1674 | 1674 | material, but Lambertian requires a $\cos(\theta_o)$ sampling pattern. So any differences that we
|
1675 | 1675 | see is because we are using a slightly different material. We're going to uniformly scatter random
|
1676 | 1676 | directions from the hemisphere and perfectly match the PDF, given by
|
1677 |
| -$\textit{pScatter}(\omega_o) = p(\omega_o) = \frac{1}{2\pi}$. |
| 1677 | +$\mathit{pScatter}(\omega_o) = p(\omega_o) = \frac{1}{2\pi}$. |
1678 | 1678 |
|
1679 | 1679 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1680 | 1680 | class lambertian : public material {
|
|
2416 | 2416 | </div>
|
2417 | 2417 |
|
2418 | 2418 | <div class='together'>
|
2419 |
| -The details of how this is done under the hood varies for $\textit{pSurface}$ and $\textit{pLight}$, but that is |
| 2419 | +The details of how this is done under the hood varies for $\mathit{pSurface}$ and $\mathit{pLight}$, but that is |
2420 | 2420 | exactly what class hierarchies were invented for! It’s never obvious what goes in an abstract class,
|
2421 | 2421 | so my approach is to be greedy and hope a minimal interface works, and for `pdf` this implies:
|
2422 | 2422 |
|
|
2735 | 2735 | mixtures of any PDFs to form mixture densities that are also PDFs. Any weighted average of PDFs is
|
2736 | 2736 | also a PDF. As long as the weights are positive and add up to any one, we have a new PDF.
|
2737 | 2737 |
|
2738 |
| - $$ \textit{pMixture}() = w_0 p_0() + w_1 p_1() + w_2 p_2() + \ldots + w_{n-1} p_{n-1}() $$ |
| 2738 | + $$ \mathit{pMixture}() = w_0 p_0() + w_1 p_1() + w_2 p_2() + \ldots + w_{n-1} p_{n-1}() $$ |
2739 | 2739 |
|
2740 | 2740 | $$ 1 = w_0 + w_1 + w_2 + \ldots + w_{n-1} $$
|
2741 | 2741 |
|
2742 | 2742 | For example, we could just average the two densities:
|
2743 | 2743 |
|
2744 |
| - $$ \textit{pMixture}(\omega_o) = \frac{1}{2} \textit{pSurface}(\omega_o) + \frac{1}{2} \textit{pLight}(\omega_o)$$ |
| 2744 | + $$ \mathit{pMixture}(\omega_o) = \frac{1}{2} \mathit{pSurface}(\omega_o) + \frac{1}{2} \mathit{pLight}(\omega_o)$$ |
2745 | 2745 |
|
2746 | 2746 | <div class='together'>
|
2747 | 2747 | How would we instrument our code to do that? There is a very important detail that makes this not
|
|
2754 | 2754 | pick direction according to pLight
|
2755 | 2755 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2756 | 2756 |
|
2757 |
| -But solving for the PDF value of $\textit{pMixture}$ is slightly more subtle. We can't just |
| 2757 | +But solving for the PDF value of $\mathit{pMixture}$ is slightly more subtle. We can't just |
2758 | 2758 |
|
2759 | 2759 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2760 | 2760 | if (direction is from pSurface)
|
|
2769 | 2769 | correct, we would have to solve backwards to figure which PDF the direction could come from. Which
|
2770 | 2770 | honestly sounds like a nightmare, but fortunately we don't need to do that. There are some
|
2771 | 2771 | directions that both PDFs could have generated. For example, a direction toward the light could have
|
2772 |
| -been generated by either $\textit{pLight}$ _or_ $\textit{pSurface}$. It is sufficient for us to solve for the pdf |
2773 |
| -value of $\textit{pSurface}$ and of $\textit{pLight}$ for a random direction and then take the PDF mixture weights to |
| 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 | 2774 | solve for the total PDF value for that direction. The mixture density class is actually pretty
|
2775 | 2775 | straightforward:
|
2776 | 2776 |
|
|
0 commit comments