Skip to content

Commit e3d26a3

Browse files
committed
Updates from progression 3, 2024-0722
1 parent d3cd909 commit e3d26a3

6 files changed

+43
-16
lines changed

books/RayTracingTheRestOfYourLife.html

+39-13
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@
18181818
see.
18191819

18201820
![<span class='num'>Image 4:</span> Cornell box, with imperfect PDF
1821-
](../images/img-3.04-cornell-refactor2.jpg class='pixel')
1821+
](../images/img-3.04-cornell-imperfect.jpg class='pixel')
18221822

18231823
Make sure to return the PDF to the scattering PDF.
18241824

@@ -1870,7 +1870,6 @@
18701870
return true;
18711871
}
18721872

1873-
18741873
double scattering_pdf(const ray& r_in, const hit_record& rec, const ray& scattered)
18751874
const override {
18761875
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -1887,7 +1886,7 @@
18871886
our uniform hemispherical diffuse. When rendering, we should get a slightly different image.
18881887

18891888
![<span class='num'>Image 5:</span> Cornell box, with uniform hemispherical sampling
1890-
](../images/img-3.04-cornell-refactor2.jpg class='pixel')
1889+
](../images/img-3.05-cornell-uniform-hemi.jpg class='pixel')
18911890

18921891
It’s pretty close to our old picture, but there are differences that are not just noise. The front
18931892
of the tall box is much more uniform in color. If you aren't sure what the best sampling pattern for
@@ -2399,7 +2398,7 @@
23992398
ray scattered;
24002399
color attenuation;
24012400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2402-
double pdf_value; // TODO: What are we supposed to do with the returned PDF?
2401+
double pdf_value;
24032402
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
24042403
color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p);
24052404

@@ -2409,6 +2408,11 @@
24092408
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
24102409
return color_from_emission;
24112410

2411+
double scattering_pdf = rec.mat->scattering_pdf(r, rec, scattered);
2412+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2413+
pdf_value = scattering_pdf;
2414+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2415+
24122416
...
24132417
}
24142418

@@ -2536,7 +2540,7 @@
25362540

25372541
ray scattered;
25382542
color attenuation;
2539-
double pdf_value; // TODO: What are we supposed to do with the returned PDF?
2543+
double pdf_value;
25402544
color color_from_emission = rec.mat->emitted(rec.u, rec.v, rec.p);
25412545

25422546
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value))
@@ -2798,7 +2802,7 @@
27982802

27992803
ray scattered;
28002804
color attenuation;
2801-
double pdf_value; // TODO: What are we supposed to do with the returned PDF?
2805+
double pdf_value;
28022806
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
28032807

28042808
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value))
@@ -2869,6 +2873,8 @@
28692873

28702874
...
28712875

2876+
2877+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
28722878
class hittable_pdf : public pdf {
28732879
public:
28742880
hittable_pdf(const hittable& objects, const point3& origin)
@@ -3034,15 +3040,15 @@
30343040

30353041
ray scattered;
30363042
color attenuation;
3037-
double pdf_value; // TODO: What are we supposed to do with the returned PDF?
3043+
double pdf_value;
30383044
color color_from_emission = rec.mat->emitted(r, rec, rec.u, rec.v, rec.p);
30393045

30403046
if (!rec.mat->scatter(r, rec, attenuation, scattered, pdf_value))
30413047
return color_from_emission;
30423048

30433049

30443050
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3045-
hittable_pdf light_pdf(light_ptr, rec.p);
3051+
hittable_pdf light_pdf(lights, rec.p);
30463052
scattered = ray(rec.p, light_pdf.generate(), r.time());
30473053
pdf_value = light_pdf.value(scattered.direction());
30483054
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -3084,6 +3090,15 @@
30843090
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
30853091

30863092
camera cam;
3093+
3094+
cam.aspect_ratio = 1.0;
3095+
cam.image_width = 600;
3096+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3097+
cam.samples_per_pixel = 10;
3098+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3099+
cam.max_depth = 50;
3100+
cam.background = color(0,0,0);
3101+
30873102
...
30883103

30893104

@@ -3203,7 +3218,7 @@
32033218

32043219

32053220
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3206-
auto p0 = make_shared<hittable_pdf>(light_ptr, rec.p);
3221+
auto p0 = make_shared<hittable_pdf>(lights, rec.p);
32073222
auto p1 = make_shared<cosine_pdf>(rec.normal);
32083223
mixture_pdf mixed_pdf(p0, p1);
32093224

@@ -3224,7 +3239,7 @@
32243239
</div>
32253240

32263241
<div class='together'>
3227-
1000 samples per pixel yields:
3242+
Updating `main.cc` to 1000 samples per pixel (not listed) yields:
32283243

32293244
![<span class='num'>Image 11:</span> Cornell box, mixture density of cosine and light sampling
32303245
](../images/img-3.11-cosine-and-light.jpg class='pixel')
@@ -3311,6 +3326,15 @@
33113326
<div class='together'>
33123327
We can redesign `material` and stuff all the new arguments into a class like we did for `hittable`:
33133328

3329+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3330+
#include "rtweekend.h"
3331+
3332+
#include "onb.h"
3333+
#include "texture.h"
3334+
3335+
class hit_record;
3336+
3337+
33143338
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
33153339
class scatter_record {
33163340
public:
@@ -3513,8 +3537,6 @@
35133537
double fuzz;
35143538
};
35153539

3516-
...
3517-
35183540
class dielectric : public material {
35193541
public:
35203542
dielectric(double refraction_index) : refraction_index(refraction_index) {}
@@ -3717,6 +3739,8 @@
37173739
public:
37183740
...
37193741

3742+
aabb bounding_box() const override { return bbox; }
3743+
37203744

37213745
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
37223746
double pdf_value(const point3& origin, const vec3& direction) const override {
@@ -3818,6 +3842,8 @@
38183842
public:
38193843
...
38203844

3845+
aabb bounding_box() const override { return bbox; }
3846+
38213847

38223848
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
38233849
double pdf_value(const point3& origin, const vec3& direction) const override {
@@ -3854,7 +3880,7 @@
38543880
hittable_list lights;
38553881
lights.add(
38563882
make_shared<quad>(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material));
3857-
lights.add(make_shared<sphere>(point3(190, 90, 190), 90, m));
3883+
lights.add(make_shared<sphere>(point3(190, 90, 190), 90, empty_material));
38583884
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
38593885

38603886
...

images/img-3.04-cornell-imperfect.jpg

217 KB
Loading

images/img-3.04-cornell-refactor2.jpg

-95.6 KB
Binary file not shown.
154 KB
Loading

images/img-3.11-cosine-and-light.jpg

159 KB
Loading

src/TheRestOfYourLife/main.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ int main() {
4747
world.add(make_shared<sphere>(point3(190,90,190), 90, glass));
4848

4949
// Light Sources
50+
auto empty_material = shared_ptr<material>();
5051
hittable_list lights;
51-
auto m = shared_ptr<material>();
52-
lights.add(make_shared<quad>(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), m));
53-
lights.add(make_shared<sphere>(point3(190, 90, 190), 90, m));
52+
lights.add(
53+
make_shared<quad>(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), empty_material));
54+
lights.add(make_shared<sphere>(point3(190, 90, 190), 90, empty_material));
5455

5556
camera cam;
5657

0 commit comments

Comments
 (0)