Skip to content

Commit d6ca90b

Browse files
authored
Update text to reflect new camera updates (#1174)
* Update text to reflect new camera updates - Clarify confusing camera nomenclature and terms - Update progression and code listing to match current camera code - Update camera figures Resolves #464 Resolves #546 Resolves #1071 * Review feedback * Review feedback
1 parent f134588 commit d6ca90b

33 files changed

+718
-392
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 579 additions & 258 deletions
Large diffs are not rendered by default.

books/RayTracingTheNextWeek.html

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,19 @@
140140
private:
141141
...
142142
ray get_ray(int i, int j) const {
143-
auto s = (i + random_double()) / (image_width - 1);
144-
auto t = (j + random_double()) / (image_height - 1);
143+
// Get a randomly-sampled camera ray for the pixel at location i,j, originating from
144+
// the camera defocus disk.
145145

146-
vec3 rd = lens_radius * random_in_unit_disk();
147-
vec3 offset = u * rd.x() + v * rd.y();
148-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
149-
auto ray_time = random_double(0.0, 1.0);
150-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
146+
auto pixel_center = pixel00_loc + (i * pixel_delta_u) + (j * pixel_delta_v);
147+
auto pixel_sample = pixel_center + pixel_sample_square();
151148

152-
return ray(
153-
origin + offset,
149+
auto ray_origin = (defocus_angle <= 0) ? center : defocus_disk_sample();
150+
auto ray_direction = pixel_sample - ray_origin;
154151
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
155-
lower_left_corner + s*horizontal + (1-t)*vertical - origin - offset,
156-
ray_time
152+
auto ray_time = random_double();
153+
154+
return ray(ray_origin, ray_direction, ray_time);
157155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
158-
);
159156
}
160157

161158
...
@@ -364,8 +361,8 @@
364361
cam.lookat = point3(0,0,0);
365362
cam.vup = vec3(0,1,0);
366363

367-
cam.aperture = 0.1;
368-
cam.focus_dist = 10.0;
364+
cam.defocus_angle = 0.02;
365+
cam.focus_dist = 10.0;
369366

370367
cam.render(world);
371368
}
@@ -1281,6 +1278,7 @@
12811278
...
12821279
}
12831280

1281+
12841282
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
12851283
void two_spheres() {
12861284
hittable_list world;
@@ -1296,14 +1294,13 @@
12961294
cam.image_width = 400;
12971295
cam.samples_per_pixel = 100;
12981296
cam.max_depth = 50;
1299-
cam.background = color(0.70, 0.80, 1.00);
13001297

1298+
cam.vfov = 20;
13011299
cam.lookfrom = point3(13,2,3);
13021300
cam.lookat = point3(0,0,0);
13031301
cam.vup = vec3(0,1,0);
1304-
cam.vfov = 20;
13051302

1306-
cam.aperture = 0;
1303+
cam.defocus_angle = 0;
13071304

13081305
cam.render(world);
13091306
}
@@ -1672,14 +1669,13 @@
16721669
cam.image_width = 400;
16731670
cam.samples_per_pixel = 100;
16741671
cam.max_depth = 50;
1675-
cam.background = color(0.70, 0.80, 1.00);
16761672

1673+
cam.vfov = 20;
16771674
cam.lookfrom = point3(0,0,12);
16781675
cam.lookat = point3(0,0,0);
16791676
cam.vup = vec3(0,1,0);
1680-
cam.vfov = 20;
16811677

1682-
cam.aperture = 0;
1678+
cam.defocus_angle = 0;
16831679

16841680
cam.render(hittable_list(globe));
16851681
}
@@ -1853,14 +1849,13 @@
18531849
cam.image_width = 400;
18541850
cam.samples_per_pixel = 100;
18551851
cam.max_depth = 50;
1856-
cam.background = color(0.70, 0.80, 1.00);
18571852

1853+
cam.vfov = 20;
18581854
cam.lookfrom = point3(13,2,3);
18591855
cam.lookat = point3(0,0,0);
18601856
cam.vup = vec3(0,1,0);
1861-
cam.vfov = 20;
18621857

1863-
cam.aperture = 0;
1858+
cam.defocus_angle = 0;
18641859

18651860
cam.render(world);
18661861
}
@@ -2839,14 +2834,13 @@
28392834
cam.image_width = 400;
28402835
cam.samples_per_pixel = 100;
28412836
cam.max_depth = 50;
2842-
cam.background = color(0.70, 0.80, 1.00);
28432837

2838+
cam.vfov = 80;
28442839
cam.lookfrom = point3(0,0,9);
28452840
cam.lookat = point3(0,0,0);
28462841
cam.vup = vec3(0,1,0);
2847-
cam.vfov = 80;
28482842

2849-
cam.aperture = 0;
2843+
cam.defocus_angle = 0;
28502844

28512845
cam.render(world);
28522846
}
@@ -2943,15 +2937,14 @@
29432937
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
29442938
class camera {
29452939
public:
2946-
double aspect_ratio = 1.0;
2947-
int image_width = 100;
2948-
int samples_per_pixel = 10;
2949-
int max_depth = 10;
2940+
double aspect_ratio = 1.0; // Ratio of image width over height
2941+
int image_width = 100; // Rendered image width in pixel count
2942+
int samples_per_pixel = 10; // Count of random samples for each pixel
2943+
int max_depth = 10; // Maximum number of ray bounces into scene
29502944
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2951-
color background = color(0,0,0);
2945+
color background; // Scene background color
29522946
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
29532947

2954-
double vfov = 40;
29552948
...
29562949

29572950
private:
@@ -3087,18 +3080,18 @@
30873080

30883081
camera cam;
30893082

3090-
cam.image_width = 400;
30913083
cam.aspect_ratio = 16.0 / 9.0;
3084+
cam.image_width = 400;
30923085
cam.samples_per_pixel = 100;
30933086
cam.max_depth = 50;
30943087
cam.background = color(0,0,0);
30953088

3089+
cam.vfov = 20;
30963090
cam.lookfrom = point3(26,3,6);
30973091
cam.lookat = point3(0,2,0);
30983092
cam.vup = vec3(0,1,0);
3099-
cam.vfov = 20;
31003093

3101-
cam.aperture = 0;
3094+
cam.defocus_angle = 0;
31023095

31033096
cam.render(world);
31043097
}
@@ -3179,12 +3172,12 @@
31793172
cam.max_depth = 50;
31803173
cam.background = color(0,0,0);
31813174

3175+
cam.vfov = 40;
31823176
cam.lookfrom = point3(278, 278, -800);
31833177
cam.lookat = point3(278, 278, 0);
31843178
cam.vup = vec3(0,1,0);
3185-
cam.vfov = 40;
31863179

3187-
cam.aperture = 0;
3180+
cam.defocus_angle = 0;
31883181

31893182
cam.render(world);
31903183
}
@@ -3828,12 +3821,12 @@
38283821
cam.max_depth = 50;
38293822
cam.background = color(0,0,0);
38303823

3824+
cam.vfov = 40;
38313825
cam.lookfrom = point3(278, 278, -800);
38323826
cam.lookat = point3(278, 278, 0);
38333827
cam.vup = vec3(0,1,0);
3834-
cam.vfov = 40;
38353828

3836-
cam.aperture = 0;
3829+
cam.defocus_angle = 0;
38373830

38383831
cam.render(world);
38393832
}
@@ -3953,12 +3946,12 @@
39533946
cam.max_depth = max_depth;
39543947
cam.background = color(0,0,0);
39553948

3949+
cam.vfov = 40;
39563950
cam.lookfrom = point3(478, 278, -600);
39573951
cam.lookat = point3(278, 278, 0);
39583952
cam.vup = vec3(0,1,0);
3959-
cam.vfov = 40;
39603953

3961-
cam.aperture = 0;
3954+
cam.defocus_angle = 0;
39623955

39633956
cam.render(world);
39643957
}

books/RayTracingTheRestOfYourLife.html

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@
287287
cam.max_depth = 50;
288288
cam.background = color(0,0,0);
289289

290+
cam.vfov = 40;
290291
cam.lookfrom = point3(278, 278, -800);
291292
cam.lookat = point3(278, 278, 0);
292293
cam.vup = vec3(0, 1, 0);
293-
cam.vfov = 40;
294294

295-
cam.aperture = 0;
295+
cam.defocus_angle = 0;
296296

297297
cam.render(world, lights);
298298
}
@@ -307,14 +307,13 @@
307307
void render(const hittable& world) {
308308
initialize();
309309

310-
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
310+
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
311311

312-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
313-
int sqrt_spp = int(sqrt(samples_per_pixel));
314312
for (int j = 0; j < image_height; ++j) {
315313
std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush;
316314
for (int i = 0; i < image_width; ++i) {
317315
color pixel_color(0,0,0);
316+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
318317
for (int s_j = 0; s_j < sqrt_spp; ++s_j) {
319318
for (int s_i = 0; s_i < sqrt_spp; ++s_i) {
320319
ray r = get_ray(i, j, s_i, s_j);
@@ -333,20 +332,33 @@
333332
...
334333
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
335334
ray get_ray(int i, int j, int s_i, int s_j) const {
336-
auto s = (i + inv_sqrt_spp * (s_i + random_double())) / (image_width - 1);
337-
auto t = (j + inv_sqrt_spp * (s_j + random_double())) / (image_height - 1);
335+
// Get a randomly-sampled camera ray for the pixel at location i,j, originating from
336+
// the camera defocus disk, and randomly sampled around the pixel location.
337+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
338+
339+
auto pixel_center = pixel00_loc + (i * pixel_delta_u) + (j * pixel_delta_v);
340+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
341+
auto pixel_sample = pixel_center + pixel_sample_square(s_i, s_j);
338342
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
339343

340-
vec3 rd = lens_radius * random_in_unit_disk();
341-
vec3 offset = u * rd.x() + v * rd.y();
342-
auto ray_time = random_double(0.0, 1.0);
344+
auto ray_origin = (defocus_angle <= 0) ? center : defocus_disk_sample();
345+
auto ray_direction = pixel_sample - ray_origin;
346+
auto ray_time = random_double();
343347

344-
return ray(
345-
origin + offset,
346-
lower_left_corner + s*horizontal + (1-t)*vertical - origin - offset,
347-
ray_time
348-
);
348+
return ray(ray_origin, ray_direction, ray_time);
349349
}
350+
351+
352+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
353+
vec3 pixel_sample_square(int s_i, int s_j) const {
354+
// Returns a random point in the square surrounding a pixel at the origin, given
355+
// the two subpixel indices.
356+
auto px = -0.5 + recip_sqrt_spp * (s_i + random_double());
357+
auto py = -0.5 + recip_sqrt_spp * (s_j + random_double());
358+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
359+
return (px * pixel_delta_u) + (py * pixel_delta_v);
360+
}
361+
350362
...
351363
};
352364
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -3556,6 +3568,8 @@
35563568
hittable_list lights;
35573569
auto m = shared_ptr<material>();
35583570
lights.add(make_shared<quad>(point3(343,554,332), vec3(-130,0,0), vec3(0,0,-105), m));
3571+
3572+
...
35593573
}
35603574
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35613575
[Listing [sampling-sphere]: <kbd>[main.cc]</kbd> Sampling just the sphere]

images/fig-1.03-cam-geom.jpg

6.28 KB
Loading

images/fig-1.04-pixel-grid.jpg

59.5 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)