Skip to content

Commit ed180dd

Browse files
committed
theNextWeek: Add custom scene image parameters
Affects scenes 5-8 Resolves #650
1 parent aea0901 commit ed180dd

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ Change Log -- Ray Tracing in One Weekend
5252
- Delete: scenes 7 & 9 from the original (`cornell_balls` and `cornell_final`), as these were not
5353
covered in the book. Made the source and book consistent with each other. There are now a total
5454
of eight scenes for the second book (#653, #620)
55-
- Change: Updated most rendered images for book 2: 2.01-2.03, 2.07-2.13, 2.15-2.22.
5655
- Change: Listing 10: Separate out world & camera definitions in main (#646)
56+
- Change: Updated most rendered images for book 2: 2.01-2.03, 2.07-2.13, 2.15-2.22.
57+
- Change: Scenes get custom image parameters (#650)
5758
- Fix: Reduced code duplication in `dielectric::scatter()` function
5859
- Fix: "Intance" typo in Chapter 8.1 to "Instance" (#629)
5960
- Fix: Listing 7: Show reverted viewing parameters from book 1 final scene

books/RayTracingTheNextWeek.html

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,9 @@
375375

376376

377377
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
378-
const auto aspect_ratio = 16.0 / 9.0;
379-
const int image_width = 400;
380-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
381-
const int image_height = static_cast<int>(image_width / aspect_ratio);
382-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
383-
const int samples_per_pixel = 100;
378+
auto aspect_ratio = 16.0 / 9.0;
379+
int image_width = 400;
380+
int samples_per_pixel = 100;
384381
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
385382
const int max_depth = 50;
386383

@@ -393,9 +390,10 @@
393390
vec3 vup(0,1,0);
394391
auto dist_to_focus = 10.0;
395392
auto aperture = 0.1;
393+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
394+
int image_height = static_cast<int>(image_width / aspect_ratio);
396395

397396

398-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
399397
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
400398
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
401399
[Listing [scene-spheres-moving-camera]: <kbd>[main.cc]</kbd> Viewing parameters]
@@ -1364,6 +1362,7 @@
13641362

13651363
vec3 vup(0,1,0);
13661364
auto dist_to_focus = 10.0;
1365+
int image_height = static_cast<int>(image_width / aspect_ratio);
13671366

13681367
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
13691368
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -2483,16 +2482,13 @@
24832482
...
24842483
int main() {
24852484
...
2486-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2487-
const int samples_per_pixel = 400;
2488-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2489-
...
24902485
switch (0) {
24912486
...
24922487
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
24932488
default:
24942489
case 5:
24952490
world = simple_light();
2491+
samples_per_pixel = 400;
24962492
background = color(0,0,0);
24972493
lookfrom = point3(26,3,6);
24982494
lookat = point3(0,2,0);
@@ -2655,11 +2651,6 @@
26552651
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
26562652

26572653
int main() {
2658-
// Image
2659-
2660-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2661-
const auto aspect_ratio = 1.0;
2662-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
26632654
...
26642655
switch (0) {
26652656
...
@@ -2675,6 +2666,9 @@
26752666
default:
26762667
case 6:
26772668
world = cornell_box();
2669+
aspect_ratio = 1.0;
2670+
image_width = 600;
2671+
samples_per_pixel = 200;
26782672
background = color(0,0,0);
26792673
lookfrom = point3(278, 278, -800);
26802674
lookat = point3(278, 278, 0);
@@ -3219,6 +3213,9 @@
32193213
default:
32203214
case 7:
32213215
world = cornell_smoke();
3216+
aspect_ratio = 1.0;
3217+
image_width = 600;
3218+
samples_per_pixel = 200;
32223219
lookfrom = point3(278, 278, -800);
32233220
lookat = point3(278, 278, 0);
32243221
vfov = 40.0;
@@ -3312,23 +3309,20 @@
33123309
}
33133310

33143311
int main() {
3315-
// Image
3316-
3317-
const auto aspect_ratio = 1.0;
3318-
const int image_width = 800;
3319-
const int image_height = static_cast<int>(image_width / aspect_ratio);
3320-
const int samples_per_pixel = 10000;
3321-
const int max_depth = 50;
33223312
...
3323-
3324-
default:
3325-
case 8:
3326-
world = final_scene();
3327-
background = color(0,0,0);
3328-
lookfrom = point3(478, 278, -600);
3329-
lookat = point3(278, 278, 0);
3330-
vfov = 40.0;
3331-
break;
3313+
switch (0) {
3314+
...
3315+
default:
3316+
case 8:
3317+
world = final_scene();
3318+
aspect_ratio = 1.0;
3319+
image_width = 800;
3320+
samples_per_pixel = 10000;
3321+
background = color(0,0,0);
3322+
lookfrom = point3(478, 278, -600);
3323+
lookat = point3(278, 278, 0);
3324+
vfov = 40.0;
3325+
break;
33323326
...
33333327
}
33343328
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

images/img-2.20-cornell-standard.png

469 KB
Loading

images/img-2.21-cornell-smoke.png

377 KB
Loading

src/TheNextWeek/main.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ int main() {
272272

273273
// Image
274274

275-
const auto aspect_ratio = 16.0 / 9.0;
276-
const int image_width = 400;
277-
const int image_height = static_cast<int>(image_width / aspect_ratio);
275+
auto aspect_ratio = 16.0 / 9.0;
276+
int image_width = 400;
278277
int samples_per_pixel = 100;
279278
int max_depth = 50;
280279

@@ -324,6 +323,7 @@ int main() {
324323

325324
case 5:
326325
world = simple_light();
326+
samples_per_pixel = 400;
327327
lookfrom = point3(26,3,6);
328328
lookat = point3(0,2,0);
329329
vfov = 20.0;
@@ -332,20 +332,29 @@ int main() {
332332
default:
333333
case 6:
334334
world = cornell_box();
335+
aspect_ratio = 1.0;
336+
image_width = 600;
337+
samples_per_pixel = 200;
335338
lookfrom = point3(278, 278, -800);
336339
lookat = point3(278, 278, 0);
337340
vfov = 40.0;
338341
break;
339342

340343
case 7:
341344
world = cornell_smoke();
345+
aspect_ratio = 1.0;
346+
image_width = 600;
347+
samples_per_pixel = 200;
342348
lookfrom = point3(278, 278, -800);
343349
lookat = point3(278, 278, 0);
344350
vfov = 40.0;
345351
break;
346352

347353
case 8:
348354
world = final_scene();
355+
aspect_ratio = 1.0;
356+
image_width = 800;
357+
samples_per_pixel = 10000;
349358
lookfrom = point3(478, 278, -600);
350359
lookat = point3(278, 278, 0);
351360
vfov = 40.0;
@@ -354,8 +363,9 @@ int main() {
354363

355364
// Camera
356365

357-
vec3 vup(0,1,0);
358-
auto dist_to_focus = 10.0;
366+
const vec3 vup(0,1,0);
367+
const auto dist_to_focus = 10.0;
368+
const int image_height = static_cast<int>(image_width / aspect_ratio);
359369

360370
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
361371

0 commit comments

Comments
 (0)