Part 6: BRDFs
The sixth part of the ray tracer contains less complicated features compared to the previous parts.
BRDFs control how much light is reflected from a surface for each incoming and outgoing light direction. They are used for computing diffuse and specular shadings at a given point. Until now, only Blinn-Phong shading model was supported. In this part, the following types of BRDFs are implemented:
1. Phong BRDF
2. Modified Phong BRDF
3. Normalized Modified Phong BRDF
4. Blinn-Phong BRDF
5. Modified Blinn-Phong BRDF
6. Normalized Modified Blinn-Phong BRDF
7. Torrance-Sparrow BRDF
The only difference of the modified versions from the original versions of the Phong and Blinn-Phong BRDFs is that the cosine terms in the denominators are removed while the rest stays the same.
Normalization is performed in order to ensure that the BRDFs are energy conserving. The formulas also ensure that the summation of diffuse reflectance constant (kd) and specular reflectance constant (ks) is less than or equal to one.
For the Torrance-Sparrow BRDF, the surface is assumed to be not perfectly flat. Instead, it is treated as if the surface is composed of little microfacets which are randomly distributed. This helps increasing the realism of the shadings.
Problems & Fixes
In this part, luckily, I did not encounter very time-consuming problems. But, some of the bugs I realized can be found below.
Firstly, the texture mapped walls in the Killeroo scenes were different from the expected outputs. This problem was not related to BRDFs, there was something wrong with texture mapping. I tried to render the old killeroo_bump_walls scene, and I realized that the walls are still rendered in a wrong way, although in the previous parts, this scene was rendered correctly. Finally, I realized that at some point I changed the texture image reading methods. While reading the texture image, I was using the number of channels returned from the read method, and for that particular image it was 1. However, I stored the pixels in 3 channels since they are represented in RGB color space. Once I fixed the mismatch between the number of channels, the problem was solved.
Secondly, in Torrance-Sparrow BRDF, I was using Schlick's Approximation while calculating the Fresnel term, which results in some difference between the produced outputs and the expected results, since the expected results are rendered with using Fresnel equations for conductors. Once I corrected the Fresnel term computation, the results turned out to be correct. The result with the Schlick's approximation can be seen below.
Resulting Images
brdf_blinnphong_original: 84 msecs 956 usecs |
brdf_blinnphong_modified: 93 msecs 609 usecs |
brdf_blinnphong_modified_normalized: 86 msecs 680 usecs |
brdf_phong_original: 92 msecs 463 usecs |
brdf_phong_modified: 93 msecs 521 usecs |
brdf_phong_modified_normalized: 84 msecs 105 usecs |
brdf_torrancesparrow: 101 msecs 395 usecs |
killeroo_blinnphong: 28 secs 168 msecs 505 usecs |
killeroo_blinnphong_closeup: 42 secs 468 msecs 694 usecs |
killeroo_torrancesparrow: 28 secs 630 msecs 292 usecs |
killeroo_torrancesparrow_closeup: 42 secs 799 msecs 200 usecs |
Comments
Post a Comment