Skip to content

Commit 458eaf7

Browse files
committed
Merge branch 'master' into dev-minor
2 parents ddd8ea7 + b4fe3dd commit 458eaf7

File tree

7 files changed

+257
-189
lines changed

7 files changed

+257
-189
lines changed

CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@ Change Log -- Ray Tracing in One Weekend
55

66

77
----------------------------------------------------------------------------------------------------
8-
# v3.1.1 (in progress)
8+
# v3.1.1 (2020-05-16)
9+
10+
### Common
11+
- Change: Camera code improvements to make it more robust when any particular value changes. Also,
12+
the code develops in a smoother series of iterations as the book progresses. (#536)
913

1014
### _In One Weekend_
15+
- Fix: Camera initialization with explicit up vector (#537)
16+
- Fix: Changed some text around the camera model and the camera defocus blur model (#536)
1117
- Change: The C++ `<random>` version of `random_double()` no longer depends on `<functional>`
12-
header
18+
header.
19+
- Change: Refactored `random_scene()`. More named intermediate values, sync'ed with source.
20+
(#489)
1321

1422
### _The Next Week_
23+
- Fix: Added clarification about updating lambertian variables from `color` to `solid_color`.
24+
- Fix: Corrected for-loop indices (they differed from the version in book 1) in `random_scene()`.
1525
- Fix: Introduce "Texture Coordinates for Spheres" in Chapter 4 to support (u,v) coordinates in
1626
`hit_record` (#496)
27+
- Fix: Small correction: we now use `std::sort` instead of `qsort` (#490)
28+
- Change: Refactored `random_scene()`. More named intermediate values, sync'ed with version in
29+
_In One Weekend_ and with source. Added highlight for update from last version in book 1. (#489)
30+
- Change: The C++ `<random>` version of `random_double()` no longer depends on `<functional>`
31+
header
1732

1833

1934
----------------------------------------------------------------------------------------------------

books/RayTracingInOneWeekend.html

Lines changed: 123 additions & 84 deletions
Large diffs are not rendered by default.

books/RayTracingTheNextWeek.html

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Peter Shirley
88
edited by Steve Hollasch and Trevor David Black
99
<br>
10-
Version 3.1.0, 2020-05-03
10+
Version 3.1.1, 2020-05-16
1111
<br>
1212
Copyright 2018-2020 Peter Shirley. All rights reserved.
1313

@@ -108,35 +108,37 @@
108108
class camera {
109109
public:
110110
camera(
111-
point3 lookfrom, point3 lookat, vec3 vup,
111+
point3 lookfrom,
112+
point3 lookat,
113+
vec3 vup,
112114
double vfov, // vertical field-of-view in degrees
113-
double aspect_ratio, double aperture, double focus_dist,
115+
double aspect_ratio,
116+
double aperture,
117+
double focus_dist,
114118
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
115-
double t0 = 0, double t1 = 0
119+
double t0 = 0,
120+
double t1 = 0
116121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
117122
) {
118-
origin = lookfrom;
119-
lens_radius = aperture / 2;
120-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
121-
time0 = t0;
122-
time1 = t1;
123-
124-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
125123
auto theta = degrees_to_radians(vfov);
126-
auto half_height = tan(theta/2);
127-
auto half_width = aspect * half_height;
124+
auto h = tan(theta/2);
125+
auto viewport_height = 2.0 * h;
126+
auto viewport_width = aspect_ratio * viewport_height;
128127

129128
w = unit_vector(lookfrom - lookat);
130129
u = unit_vector(cross(vup, w));
131130
v = cross(w, u);
132131

133-
lower_left_corner = origin
134-
- half_width*focus_dist*u
135-
- half_height*focus_dist*v
136-
- focus_dist*w;
132+
origin = lookfrom;
133+
horizontal = focus_dist * viewport_width * u;
134+
vertical = focus_dist * viewport_height * v;
135+
lower_left_corner = origin - horizontal/2 - vertical/2 - focus_dist*w;
137136

138-
horizontal = 2*half_width*focus_dist*u;
139-
vertical = 2*half_height*focus_dist*v;
137+
lens_radius = aperture / 2;
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
139+
time0 = t0;
140+
time1 = t1;
141+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
140142
}
141143

142144
ray get_ray(double s, double t) const {
@@ -292,40 +294,49 @@
292294
hittable_list random_scene() {
293295
hittable_list world;
294296

295-
world.add(make_shared<sphere>(
296-
point3(0,-1000,0), 1000, make_shared<lambertian>(color(0.5, 0.5, 0.5))));
297+
auto ground_material = make_shared<lambertian>(color(0.5, 0.5, 0.5));
298+
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material));
297299

298-
int i = 1;
299-
for (int a = -10; a < 10; a++) {
300-
for (int b = -10; b < 10; b++) {
300+
for (int a = -11; a < 11; a++) {
301+
for (int b = -11; b < 11; b++) {
301302
auto choose_mat = random_double();
302303
point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
303-
if ((center - vec3(4, .2, 0)).length() > 0.9) {
304+
305+
if ((center - vec3(4, 0.2, 0)).length() > 0.9) {
306+
shared_ptr<material> sphere_material;
307+
304308
if (choose_mat < 0.8) {
305309
// diffuse
306310
auto albedo = color::random() * color::random();
311+
sphere_material = make_shared<lambertian>(albedo);
312+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
313+
auto center2 = center + vec3(0, random_double(0,.5), 0);
307314
world.add(make_shared<moving_sphere>(
308-
center, center + vec3(0, random_double(0,.5), 0), 0.0, 1.0, 0.2,
309-
make_shared<lambertian>(albedo)));
315+
center, center2, 0.0, 1.0, 0.2, sphere_material));
316+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
310317
} else if (choose_mat < 0.95) {
311318
// metal
312-
auto albedo = color::random(.5, 1);
313-
auto fuzz = random_double(0, .5);
314-
world.add(
315-
make_shared<sphere>(center, 0.2, make_shared<metal>(albedo, fuzz)));
319+
auto albedo = color::random(0.5, 1);
320+
auto fuzz = random_double(0, 0.5);
321+
sphere_material = make_shared<metal>(albedo, fuzz);
322+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
316323
} else {
317324
// glass
318-
world.add(make_shared<sphere>(center, 0.2, make_shared<dielectric>(1.5)));
325+
sphere_material = make_shared<dielectric>(1.5);
326+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
319327
}
320328
}
321329
}
322330
}
323331

324-
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, make_shared<dielectric>(1.5)));
325-
world.add(make_shared<sphere>(
326-
point3(-4, 1, 0), 1.0, make_shared<lambertian>(color(0.4, 0.2, 0.1))));
327-
world.add(make_shared<sphere>(
328-
point3(4, 1, 0), 1.0, make_shared<metal>(color(0.7, 0.6, 0.5), 0.0)));
332+
auto material1 = make_shared<dielectric>(1.5);
333+
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
334+
335+
auto material2 = make_shared<lambertian>(color(0.4, 0.2, 0.1));
336+
world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
337+
338+
auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0);
339+
world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
329340

330341
return world;
331342
}
@@ -802,7 +813,7 @@
802813
list along one axis. I’ll go for simplicity:
803814

804815
1. randomly choose an axis
805-
2. sort the primitives using library qsort
816+
2. sort the primitives (`using std::sort`)
806817
3. put half in each subtree
807818

808819
</div>
@@ -1054,7 +1065,7 @@
10541065
</div>
10551066

10561067
<div class='together'>
1057-
Where you used to have
1068+
Where you used to have code like this:
10581069

10591070
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
10601071
...make_shared<lambertian>(color(0.5, 0.5, 0.5))
@@ -1067,6 +1078,8 @@
10671078
...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5))
10681079
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10691080
[Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture]
1081+
1082+
Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`.
10701083
</div>
10711084

10721085

@@ -1107,7 +1120,8 @@
11071120

11081121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
11091122
auto checker = make_shared<checker_texture>(
1110-
make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9)
1123+
make_shared<solid_color>(0.2, 0.3, 0.1),
1124+
make_shared<solid_color>(0.9, 0.9, 0.9)
11111125
);
11121126

11131127
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker)));
@@ -1131,7 +1145,8 @@
11311145
hittable_list objects;
11321146

11331147
auto checker = make_shared<checker_texture>(
1134-
make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9)
1148+
make_shared<solid_color>(0.2, 0.3, 0.1),
1149+
make_shared<solid_color>(0.9, 0.9, 0.9)
11351150
);
11361151

11371152
objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker)));

books/RayTracingTheRestOfYourLife.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Peter Shirley
88
edited by Steve Hollasch and Trevor David Black
99
<br>
10-
Version 3.1.0, 2020-05-03
10+
Version 3.1.1, 2020-05-16
1111
<br>
1212
Copyright 2018-2020 Peter Shirley. All rights reserved.
1313

src/InOneWeekend/main.cc

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,45 @@ color ray_color(const ray& r, const hittable& world, int depth) {
4444
hittable_list random_scene() {
4545
hittable_list world;
4646

47-
world.add(
48-
make_shared<sphere>(
49-
point3(0,-1000,0), 1000, make_shared<lambertian>(color(0.5, 0.5, 0.5)))
50-
);
47+
auto ground_material = make_shared<lambertian>(color(0.5, 0.5, 0.5));
48+
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material));
5149

52-
int i = 1;
5350
for (int a = -11; a < 11; a++) {
5451
for (int b = -11; b < 11; b++) {
5552
auto choose_mat = random_double();
5653
point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
54+
5755
if ((center - vec3(4, 0.2, 0)).length() > 0.9) {
56+
shared_ptr<material> sphere_material;
57+
5858
if (choose_mat < 0.8) {
5959
// diffuse
6060
auto albedo = color::random() * color::random();
61-
world.add(
62-
make_shared<sphere>(center, 0.2, make_shared<lambertian>(albedo)));
61+
sphere_material = make_shared<lambertian>(albedo);
62+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
6363
} else if (choose_mat < 0.95) {
6464
// metal
65-
auto albedo = color::random(.5, 1);
66-
auto fuzz = random_double(0, .5);
67-
world.add(
68-
make_shared<sphere>(center, 0.2, make_shared<metal>(albedo, fuzz)));
65+
auto albedo = color::random(0.5, 1);
66+
auto fuzz = random_double(0, 0.5);
67+
sphere_material = make_shared<metal>(albedo, fuzz);
68+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
6969
} else {
7070
// glass
71-
world.add(make_shared<sphere>(center, 0.2, make_shared<dielectric>(1.5)));
71+
sphere_material = make_shared<dielectric>(1.5);
72+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
7273
}
7374
}
7475
}
7576
}
7677

77-
world.add(
78-
make_shared<sphere>(
79-
point3(0, 1, 0), 1.0, make_shared<dielectric>(1.5)));
78+
auto material1 = make_shared<dielectric>(1.5);
79+
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
8080

81-
world.add(
82-
make_shared<sphere>(
83-
point3(-4, 1, 0), 1.0, make_shared<lambertian>(color(0.4, 0.2, 0.1))));
81+
auto material2 = make_shared<lambertian>(color(0.4, 0.2, 0.1));
82+
world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
8483

85-
world.add(
86-
make_shared<sphere>(
87-
point3(4, 1, 0), 1.0, make_shared<metal>(color(0.7, 0.6, 0.5), 0.0)));
84+
auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0);
85+
world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
8886

8987
return world;
9088
}

src/TheNextWeek/main.cc

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,44 @@ hittable_list random_scene() {
5757

5858
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker)));
5959

60-
for (int a = -10; a < 10; a++) {
61-
for (int b = -10; b < 10; b++) {
60+
for (int a = -11; a < 11; a++) {
61+
for (int b = -11; b < 11; b++) {
6262
auto choose_mat = random_double();
6363
point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
64-
if ((center - vec3(4, .2, 0)).length() > 0.9) {
64+
65+
if ((center - vec3(4, 0.2, 0)).length() > 0.9) {
66+
shared_ptr<material> sphere_material;
67+
6568
if (choose_mat < 0.8) {
6669
// diffuse
6770
auto albedo = color::random() * color::random();
71+
sphere_material = make_shared<lambertian>(make_shared<solid_color>(albedo));
72+
auto center2 = center + vec3(0, random_double(0,.5), 0);
6873
world.add(make_shared<moving_sphere>(
69-
center, center + vec3(0, random_double(0,.5), 0), 0.0, 1.0, 0.2,
70-
make_shared<lambertian>(make_shared<solid_color>(albedo))
71-
));
74+
center, center2, 0.0, 1.0, 0.2, sphere_material));
7275
} else if (choose_mat < 0.95) {
7376
// metal
74-
auto albedo = color::random(.5, 1);
75-
auto fuzz = random_double(0, .5);
76-
world.add(
77-
make_shared<sphere>(center, 0.2, make_shared<metal>(albedo, fuzz)));
77+
auto albedo = color::random(0.5, 1);
78+
auto fuzz = random_double(0, 0.5);
79+
sphere_material = make_shared<metal>(albedo, fuzz);
80+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
7881
} else {
7982
// glass
80-
world.add(make_shared<sphere>(center, 0.2, make_shared<dielectric>(1.5)));
83+
sphere_material = make_shared<dielectric>(1.5);
84+
world.add(make_shared<sphere>(center, 0.2, sphere_material));
8185
}
8286
}
8387
}
8488
}
8589

86-
world.add(make_shared<sphere>(point3(0,1,0), 1.0, make_shared<dielectric>(1.5)));
90+
auto material1 = make_shared<dielectric>(1.5);
91+
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
8792

88-
world.add(
89-
make_shared<sphere>(
90-
point3(-4,1,0), 1.0,
91-
make_shared<lambertian>(make_shared<solid_color>(0.4, 0.2, 0.1))
92-
)
93-
);
93+
auto material2 = make_shared<lambertian>(make_shared<solid_color>(color(0.4, 0.2, 0.1)));
94+
world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
9495

95-
world.add(
96-
make_shared<sphere>(
97-
point3(4,1,0), 1.0, make_shared<metal>(color(0.7, 0.6, 0.5), 0.0)
98-
)
99-
);
96+
auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0);
97+
world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
10098

10199
return hittable_list(make_shared<bvh_node>(world, 0.0, 1.0));
102100
}
@@ -106,7 +104,8 @@ hittable_list two_spheres() {
106104
hittable_list objects;
107105

108106
auto checker = make_shared<checker_texture>(
109-
make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9)
107+
make_shared<solid_color>(0.2, 0.3, 0.1),
108+
make_shared<solid_color>(0.9, 0.9, 0.9)
110109
);
111110

112111
objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker)));

0 commit comments

Comments
 (0)