Skip to content

Commit 4002df0

Browse files
committed
Updates from progression 2024-04-05
Some minor fixes, plus lots of reconciliation between book 2, book 2 source, and book 3 source.
1 parent f958592 commit 4002df0

File tree

9 files changed

+44
-38
lines changed

9 files changed

+44
-38
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
cam.lookat = point3(0,0,0);
356356
cam.vup = vec3(0,1,0);
357357

358-
cam.defocus_angle = 0.02;
358+
cam.defocus_angle = 0.6;
359359
cam.focus_dist = 10.0;
360360

361361
cam.render(world);
@@ -713,8 +713,8 @@
713713
class sphere : public hittable {
714714
public:
715715
// Stationary Sphere
716-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
717716
sphere(const point3& center, double radius, shared_ptr<material> mat)
717+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
718718
: center1(center), radius(fmax(0,radius)), mat(mat), is_moving(false)
719719
{
720720
auto rvec = vec3(radius, radius, radius);
@@ -1086,6 +1086,7 @@
10861086
#include "bvh.h"
10871087
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
10881088
#include "camera.h"
1089+
#include "hittable.h"
10891090
#include "hittable_list.h"
10901091
#include "material.h"
10911092
#include "sphere.h"
@@ -1251,16 +1252,16 @@
12511252

12521253
class solid_color : public texture {
12531254
public:
1254-
solid_color(const color& albedo) : color_value(albedo) {}
1255+
solid_color(const color& albedo) : albedo(albedo) {}
12551256

12561257
solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {}
12571258

12581259
color value(double u, double v, const point3& p) const override {
1259-
return color_value;
1260+
return albedo;
12601261
}
12611262

12621263
private:
1263-
color color_value;
1264+
color albedo;
12641265
};
12651266

12661267
#endif
@@ -1403,6 +1404,7 @@
14031404

14041405
#include "bvh.h"
14051406
#include "camera.h"
1407+
#include "hittable.h"
14061408
#include "hittable_list.h"
14071409
#include "material.h"
14081410
#include "sphere.h"
@@ -1454,6 +1456,7 @@
14541456

14551457
#include "bvh.h"
14561458
#include "camera.h"
1459+
#include "hittable.h"
14571460
#include "hittable_list.h"
14581461
#include "material.h"
14591462
#include "sphere.h"
@@ -1493,6 +1496,7 @@
14931496

14941497
#include "bvh.h"
14951498
#include "camera.h"
1499+
#include "hittable.h"
14961500
#include "hittable_list.h"
14971501
#include "material.h"
14981502
#include "sphere.h"
@@ -2020,7 +2024,7 @@
20202024
static int* perlin_generate_perm() {
20212025
auto p = new int[point_count];
20222026

2023-
for (int i = 0; i < perlin::point_count; i++)
2027+
for (int i = 0; i < point_count; i++)
20242028
p[i] = i;
20252029

20262030
permute(p, point_count);
@@ -2491,7 +2495,7 @@
24912495
auto weight = 1.0;
24922496

24932497
for (int i = 0; i < depth; i++) {
2494-
accum += weight*noise(temp_p);
2498+
accum += weight * noise(temp_p);
24952499
weight *= 0.5;
24962500
temp_p *= 2;
24972501
}
@@ -3126,7 +3130,7 @@
31263130

31273131
#include "bvh.h"
31283132
#include "camera.h"
3129-
#include "color.h"
3133+
#include "hittable.h"
31303134
#include "hittable_list.h"
31313135
#include "material.h"
31323136
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -3679,7 +3683,7 @@
36793683
// Move the ray backwards by the offset
36803684
ray offset_r(r.origin() - offset, r.direction(), r.time());
36813685

3682-
// Determine where (if any) an intersection occurs along the offset ray
3686+
// Determine whether an intersection exists along the offset ray (and if so, where)
36833687
if (!object->hit(offset_r, ray_t, rec))
36843688
return false;
36853689

@@ -3869,7 +3873,7 @@
38693873

38703874
ray rotated_r(origin, direction, r.time());
38713875

3872-
// Determine where (if any) an intersection occurs in object space
3876+
// Determine whether an intersection exists in object space (and if so, where)
38733877
if (!object->hit(rotated_r, ray_t, rec))
38743878
return false;
38753879

@@ -4038,12 +4042,14 @@
40384042

40394043
class constant_medium : public hittable {
40404044
public:
4041-
constant_medium(shared_ptr<hittable> b, double d, shared_ptr<texture> a)
4042-
: boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(a))
4045+
constant_medium(shared_ptr<hittable> boundary, double density, shared_ptr<texture> tex)
4046+
: boundary(boundary), neg_inv_density(-1/density),
4047+
phase_function(make_shared<isotropic>(tex))
40434048
{}
40444049

4045-
constant_medium(shared_ptr<hittable> b, double d, const color& c)
4046-
: boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(c))
4050+
constant_medium(shared_ptr<hittable> boundary, double density, const color& albedo)
4051+
: boundary(boundary), neg_inv_density(-1/density),
4052+
phase_function(make_shared<isotropic>(albedo))
40474053
{}
40484054

40494055
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
@@ -4059,7 +4065,7 @@
40594065
if (!boundary->hit(r, interval(rec1.t+0.0001, infinity), rec2))
40604066
return false;
40614067

4062-
if (debugging) std::clog << "\nray_tmin=" << rec1.t << ", ray_tmax=" << rec2.t << '\n';
4068+
if (debugging) std::clog << "\nt_min=" << rec1.t << ", t_max=" << rec2.t << '\n';
40634069

40644070
if (rec1.t < ray_t.min) rec1.t = ray_t.min;
40654071
if (rec2.t > ray_t.max) rec2.t = ray_t.max;
@@ -4119,13 +4125,13 @@
41194125
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
41204126
class isotropic : public material {
41214127
public:
4122-
isotropic(const color& c) : tex(make_shared<solid_color>(c)) {}
4128+
isotropic(const color& albedo) : tex(make_shared<solid_color>(albedo)) {}
41234129
isotropic(shared_ptr<texture> tex) : tex(tex) {}
41244130

41254131
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
41264132
const override {
4127-
attenuation = tex->value(rec.u, rec.v, rec.p);
41284133
scattered = ray(rec.p, random_unit_vector(), r_in.time());
4134+
attenuation = tex->value(rec.u, rec.v, rec.p);
41294135
return true;
41304136
}
41314137

@@ -4158,10 +4164,10 @@
41584164

41594165
#include "bvh.h"
41604166
#include "camera.h"
4161-
#include "color.h"
41624167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
41634168
#include "constant_medium.h"
41644169
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
4170+
#include "hittable.h"
41654171
#include "hittable_list.h"
41664172
#include "material.h"
41674173
#include "quad.h"

src/TheNextWeek/constant_medium.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class constant_medium : public hittable {
2525
phase_function(make_shared<isotropic>(tex))
2626
{}
2727

28-
constant_medium(shared_ptr<hittable> boundary, double density, const color& c)
28+
constant_medium(shared_ptr<hittable> boundary, double density, const color& albedo)
2929
: boundary(boundary), neg_inv_density(-1/density),
30-
phase_function(make_shared<isotropic>(c))
30+
phase_function(make_shared<isotropic>(albedo))
3131
{}
3232

3333
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {

src/TheNextWeek/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void bouncing_spheres() {
8181
cam.lookat = point3(0,0,0);
8282
cam.vup = vec3(0,1,0);
8383

84-
cam.defocus_angle = 0.02;
85-
cam.focus_dist = 10;
84+
cam.defocus_angle = 0.6;
85+
cam.focus_dist = 10.0;
8686

8787
cam.render(world);
8888
}

src/TheNextWeek/perlin.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class perlin {
9090

9191
static void permute(int* p, int n) {
9292
for (int i = n-1; i > 0; i--) {
93-
int target = random_int(0,i);
93+
int target = random_int(0, i);
9494
int tmp = p[i];
9595
p[i] = p[target];
9696
p[target] = tmp;
@@ -107,9 +107,10 @@ class perlin {
107107
for (int j=0; j < 2; j++)
108108
for (int k=0; k < 2; k++) {
109109
vec3 weight_v(u-i, v-j, w-k);
110-
accum += (i*uu + (1-i)*(1-uu))*
111-
(j*vv + (1-j)*(1-vv))*
112-
(k*ww + (1-k)*(1-ww))*dot(c[i][j][k], weight_v);
110+
accum += (i*uu + (1-i)*(1-uu))
111+
* (j*vv + (1-j)*(1-vv))
112+
* (k*ww + (1-k)*(1-ww))
113+
* dot(c[i][j][k], weight_v);
113114
}
114115

115116
return accum;

src/TheNextWeek/texture.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class solid_color : public texture {
2929
public:
3030
solid_color(const color& albedo) : albedo(albedo) {}
3131

32-
solid_color(double red, double green, double blue)
33-
: solid_color(color(red,green,blue)) {}
32+
solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {}
3433

3534
color value(double u, double v, const point3& p) const override {
3635
return albedo;

src/TheRestOfYourLife/camera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class camera {
9393
vec3 viewport_u = viewport_width * u; // Vector across viewport horizontal edge
9494
vec3 viewport_v = viewport_height * -v; // Vector down viewport vertical edge
9595

96-
// Calculate the horizontal and vertical delta vectors to the next pixel.
96+
// Calculate the horizontal and vertical delta vectors from pixel to pixel.
9797
pixel_delta_u = viewport_u / image_width;
9898
pixel_delta_v = viewport_v / image_height;
9999

@@ -134,7 +134,7 @@ class camera {
134134
}
135135

136136
vec3 sample_square() const {
137-
// Returns a random point in the square surrounding a pixel at the origin.
137+
// Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square.
138138
return vec3(random_double() - 0.5, random_double() - 0.5, 0);
139139
}
140140

src/TheRestOfYourLife/constant_medium.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class constant_medium : public hittable {
2525
phase_function(make_shared<isotropic>(tex))
2626
{}
2727

28-
constant_medium(shared_ptr<hittable> boundary, double density, const color& c)
28+
constant_medium(shared_ptr<hittable> boundary, double density, const color& albedo)
2929
: boundary(boundary), neg_inv_density(-1/density),
30-
phase_function(make_shared<isotropic>(c))
30+
phase_function(make_shared<isotropic>(albedo))
3131
{}
3232

3333
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {

src/TheRestOfYourLife/perlin.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class perlin {
9090

9191
static void permute(int* p, int n) {
9292
for (int i = n-1; i > 0; i--) {
93-
int target = random_int(0,i);
93+
int target = random_int(0, i);
9494
int tmp = p[i];
9595
p[i] = p[target];
9696
p[target] = tmp;
@@ -107,9 +107,10 @@ class perlin {
107107
for (int j=0; j < 2; j++)
108108
for (int k=0; k < 2; k++) {
109109
vec3 weight_v(u-i, v-j, w-k);
110-
accum += (i*uu + (1-i)*(1-uu))*
111-
(j*vv + (1-j)*(1-vv))*
112-
(k*ww + (1-k)*(1-ww))*dot(c[i][j][k], weight_v);
110+
accum += (i*uu + (1-i)*(1-uu))
111+
* (j*vv + (1-j)*(1-vv))
112+
* (k*ww + (1-k)*(1-ww))
113+
* dot(c[i][j][k], weight_v);
113114
}
114115

115116
return accum;

src/TheRestOfYourLife/texture.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class solid_color : public texture {
2929
public:
3030
solid_color(const color& albedo) : albedo(albedo) {}
3131

32-
solid_color(double red, double green, double blue)
33-
: solid_color(color(red,green,blue)) {}
32+
solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {}
3433

3534
color value(double u, double v, const point3& p) const override {
3635
return albedo;

0 commit comments

Comments
 (0)