|
1309 | 1309 | least for ray tracing--is producing a random direction. In the first two books we generated a random
|
1310 | 1310 | direction by creating a random vector and rejecting it if it fell outside of the unit sphere. We
|
1311 | 1311 | repeated this process until we found a random vector that fell inside the unit sphere. Normalizing
|
1312 |
| -this vector produced points that lay exactly on the unit sphere and thereby producing a random |
1313 |
| -direction. This process of generating samples and rejecting them if they are not inside of a desired |
1314 |
| -space is called _the rejection method_ and is found all over the literature. The method covered last |
1315 |
| -chapter is referred to as _the inversion method_ because we invert a PDF. |
| 1312 | +this vector produced points that lay exactly on the unit sphere and thereby represent a random |
| 1313 | +direction. This process of generating samples and rejecting them if they are not inside a desired |
| 1314 | +space is called _the rejection method_, and is found all over the literature. The method covered |
| 1315 | +last chapter is referred to as _the inversion method_ because we invert a PDF. |
1316 | 1316 |
|
1317 | 1317 | Every direction in 3D space has an associated point on the unit sphere and can be generated by
|
1318 | 1318 | solving for the vector that travels from the origin to that associated point. You can think of
|
|
1437 | 1437 | wavelength of the light: $\mathit{pScatter}(\omega_i, \omega_o, \lambda)$. A good example
|
1438 | 1438 | of this is a prism refracting white light into a rainbow. Lastly, the scattering PDF can also depend
|
1439 | 1439 | on the scattering position: $\mathit{pScatter}(\mathbf{x}, \omega_i, \omega_o, \lambda)$. The
|
1440 |
| -$\mathbf{x}$ is just a vector representing the scattering position: $\mathbf{x} = (x, y, z)$. The |
1441 |
| -albedo of an object can also depend on these quantities: |
1442 |
| -$A(\mathbf{x}, \omega_i, \omega_o, \lambda)$. |
| 1440 | +$\mathbf{x}$ is just math notation for the scattering position: $\mathbf{x} = (x, y, z)$. The albedo |
| 1441 | +of an object can also depend on these quantities: $A(\mathbf{x}, \omega_i, \omega_o, \lambda)$. |
1443 | 1442 |
|
1444 | 1443 | <div class='together'>
|
1445 | 1444 | The color of a surface is found by integrating these terms over the unit hemisphere by the incident
|
|
1543 | 1542 | Playing with Importance Sampling
|
1544 | 1543 | ====================================================================================================
|
1545 | 1544 | <div class='together'>
|
1546 |
| -Our goal over the next four chapters is to instrument our program to send a bunch of extra rays |
| 1545 | +Our goal over the next several chapters is to instrument our program to send a bunch of extra rays |
1547 | 1546 | toward light sources so that our picture is less noisy. Let’s assume we can send a bunch of rays
|
1548 | 1547 | toward the light source using a PDF $\mathit{pLight}(\omega_o)$. Let’s also assume we have a PDF
|
1549 | 1548 | related to $\mathit{pScatter}$, and let’s call that $\mathit{pSurface}(\omega_o)$. A great thing
|
|
1599 | 1598 | </div>
|
1600 | 1599 |
|
1601 | 1600 | First, let’s instrument the code so that it explicitly samples some PDF and then normalizes for
|
1602 |
| -that. Remember Monte Carlo basics: $\int f(x) \approx \sum f(r)/p(r)$. For the Lambertian material, let’s |
1603 |
| -sample like we do now: $p(\omega_o) = \cos(\theta_o) / \pi$. |
| 1601 | +that. Remember Monte Carlo basics: $\int f(x) \approx \sum f(r)/p(r)$. For the Lambertian material, |
| 1602 | +let’s sample like we do now: $p(\omega_o) = \cos(\theta_o) / \pi$. |
1604 | 1603 |
|
1605 | 1604 | <div class='together'>
|
1606 | 1605 | We modify the base-class `material` to enable this importance sampling:
|
|
1702 | 1701 | The ray_color function, modified for importance sampling]
|
1703 | 1702 | </div>
|
1704 | 1703 |
|
1705 |
| -You should get exactly the same picture. Which, _should make sense_, as the scattered part of |
| 1704 | +You should get exactly the same picture. Which _should make sense_, as the scattered part of |
1706 | 1705 | `ray_color` is getting multiplied by `scattering_pdf / pdf`, and as `pdf` is equal to
|
1707 | 1706 | `scattering_pdf` is just the same as multiplying by one.
|
1708 | 1707 |
|
|
1788 | 1787 | attempt to repeat the uniform hemispherical scattering from the first book. There's nothing wrong
|
1789 | 1788 | with this technique, but we are no longer treating our objects as Lambertian. Lambertian is a
|
1790 | 1789 | specific type of diffuse material that requires a $\cos(\theta_o)$ scattering distribution.
|
1791 |
| -Uniform hemispherical scattering is another diffuse material, albeit a different one. If we keep the |
1792 |
| -material the same but change the PDF, as we did in last section, we will still converge on the same |
1793 |
| -answer, but our convergence may take more or less samples. However, if we change the material, we |
1794 |
| -will have fundamentally changed the render and the algorithm will converge on a different answer. So |
1795 |
| -when we replace Lambertian diffuse with uniform hemispherical diffuse we should expect that the |
1796 |
| -outcome of our render to be _materially_ different. We're going to adjust our scattering direction |
1797 |
| -and scattering PDF: |
| 1790 | +Uniform hemispherical scattering is a different diffuse material. If we keep the material the same |
| 1791 | +but change the PDF, as we did in last section, we will still converge on the same answer, but our |
| 1792 | +convergence may take more or less samples. However, if we change the material, we will have |
| 1793 | +fundamentally changed the render and the algorithm will converge on a different answer. So when we |
| 1794 | +replace Lambertian diffuse with uniform hemispherical diffuse we should expect the outcome of our |
| 1795 | +render to be _materially_ different. We're going to adjust our scattering direction and scattering |
| 1796 | +PDF: |
1798 | 1797 |
|
1799 | 1798 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1800 | 1799 | class lambertian : public material {
|
|
0 commit comments