Skip to content

Commit f134588

Browse files
committed
Change book2 to final parameterized scene
Instead of passing a "high quality" flag, pass in the image size, samples per pixel and max depth directly for simplicity and clarity.
1 parent b4d5365 commit f134588

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,7 +3884,7 @@
38843884
...
38853885

38863886
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3887-
void final_scene(bool high_quality) {
3887+
void final_scene(int image_width, int samples_per_pixel, int max_depth) {
38883888
hittable_list boxes1;
38893889
auto ground = make_shared<lambertian>(color(0.48, 0.83, 0.53));
38903890

@@ -3947,8 +3947,11 @@
39473947

39483948
camera cam;
39493949

3950-
cam.aspect_ratio = 1.0;
3951-
cam.background = color(0,0,0);
3950+
cam.aspect_ratio = 1.0;
3951+
cam.image_width = image_width;
3952+
cam.samples_per_pixel = samples_per_pixel;
3953+
cam.max_depth = max_depth;
3954+
cam.background = color(0,0,0);
39523955

39533956
cam.lookfrom = point3(478, 278, -600);
39543957
cam.lookat = point3(278, 278, 0);
@@ -3957,16 +3960,6 @@
39573960

39583961
cam.aperture = 0;
39593962

3960-
if (high_quality) {
3961-
cam.image_width = 800;
3962-
cam.samples_per_pixel = 10000;
3963-
cam.max_depth = 50;
3964-
} else {
3965-
cam.image_width = 400;
3966-
cam.samples_per_pixel = 250;
3967-
cam.max_depth = 4;
3968-
}
3969-
39703963
cam.render(world);
39713964
}
39723965
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -3975,17 +3968,17 @@
39753968
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
39763969
switch (0) {
39773970
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
3978-
case 1: random_spheres(); break;
3979-
case 2: two_spheres(); break;
3980-
case 3: earth(); break;
3981-
case 4: two_perlin_spheres(); break;
3982-
case 5: quads(); break;
3983-
case 6: simple_light(); break;
3984-
case 7: cornell_box(); break;
3985-
case 8: cornell_smoke(); break;
3986-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3987-
case 9: final_scene(true); break;
3988-
default: final_scene(false); break;
3971+
case 1: random_spheres(); break;
3972+
case 2: two_spheres(); break;
3973+
case 3: earth(); break;
3974+
case 4: two_perlin_spheres(); break;
3975+
case 5: quads(); break;
3976+
case 6: simple_light(); break;
3977+
case 7: cornell_box(); break;
3978+
case 8: cornell_smoke(); break;
3979+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3980+
case 9: final_scene(800, 10000, 40); break;
3981+
default: final_scene(400, 250, 4); break;
39893982
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
39903983
}
39913984
}

src/TheNextWeek/main.cc

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void cornell_smoke() {
320320
}
321321

322322

323-
void final_scene(bool high_quality) {
323+
void final_scene(int image_width, int samples_per_pixel, int max_depth) {
324324
hittable_list boxes1;
325325
auto ground = make_shared<lambertian>(color(0.48, 0.83, 0.53));
326326

@@ -383,8 +383,11 @@ void final_scene(bool high_quality) {
383383

384384
camera cam;
385385

386-
cam.aspect_ratio = 1.0;
387-
cam.background = color(0,0,0);
386+
cam.aspect_ratio = 1.0;
387+
cam.image_width = image_width;
388+
cam.samples_per_pixel = samples_per_pixel;
389+
cam.max_depth = max_depth;
390+
cam.background = color(0,0,0);
388391

389392
cam.lookfrom = point3(478, 278, -600);
390393
cam.lookat = point3(278, 278, 0);
@@ -393,31 +396,21 @@ void final_scene(bool high_quality) {
393396

394397
cam.defocus_angle = 0;
395398

396-
if (high_quality) {
397-
cam.image_width = 800;
398-
cam.samples_per_pixel = 10000;
399-
cam.max_depth = 50;
400-
} else {
401-
cam.image_width = 400;
402-
cam.samples_per_pixel = 250;
403-
cam.max_depth = 4;
404-
}
405-
406399
cam.render(world);
407400
}
408401

409402

410403
int main() {
411404
switch (0) {
412-
case 1: random_spheres(); break;
413-
case 2: two_spheres(); break;
414-
case 3: earth(); break;
415-
case 4: two_perlin_spheres(); break;
416-
case 5: quads(); break;
417-
case 6: simple_light(); break;
418-
case 7: cornell_box(); break;
419-
case 8: cornell_smoke(); break;
420-
case 9: final_scene(true); break;
421-
default: final_scene(false); break;
405+
case 1: random_spheres(); break;
406+
case 2: two_spheres(); break;
407+
case 3: earth(); break;
408+
case 4: two_perlin_spheres(); break;
409+
case 5: quads(); break;
410+
case 6: simple_light(); break;
411+
case 7: cornell_box(); break;
412+
case 8: cornell_smoke(); break;
413+
case 9: final_scene(800, 10000, 40); break;
414+
default: final_scene(400, 250, 4); break;
422415
}
423416
}

0 commit comments

Comments
 (0)