Skip to content

Commit 351a3fe

Browse files
authored
More updates from book 1 progression
Small remaining tweaks to book 1. In general, update source code to match updates from book 1. material.h: Fix material metal fuzz missed conversions from random_in_unit_sphere() to random_unit_vector(). See PR #1159. Carried source updates from book 1 forward to the other two books' source code.
1 parent b3fc9b5 commit 351a3fe

30 files changed

+58
-54
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,9 @@
11281128
auto c = oc.length_squared() - radius*radius;
11291129

11301130
auto discriminant = h*h - a*c;
1131-
if (discriminant < 0) return false;
1131+
if (discriminant < 0)
1132+
return false;
1133+
11321134
auto sqrtd = sqrt(discriminant);
11331135

11341136
// Find the nearest root that lies in the acceptable range.
@@ -1436,8 +1438,6 @@
14361438
assumption in mind.
14371439

14381440
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1439-
#include "vec3.h"
1440-
14411441
#include <iostream>
14421442
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14431443
[Listing [assume-rtw-color]: <kbd>[color.h]</kbd> Assume rtweekend.h inclusion for color.h]
@@ -1490,6 +1490,8 @@
14901490

14911491
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
14921492
#include "color.h"
1493+
#include "ray.h"
1494+
#include "vec3.h"
14931495
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14941496
#include "hittable.h"
14951497
#include "hittable_list.h"
@@ -2042,7 +2044,9 @@
20422044
return distribution(generator);
20432045
}
20442046
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2045-
[Listing [random-double-alt]: <kbd>[rtweekend.h]</kbd> random_double(), alternate implemenation]
2047+
[Listing [random-double-alt]: <kbd>[rtweekend.h]</kbd>
2048+
random_double(), alternate implementation
2049+
]
20462050

20472051

20482052
Generating Pixels with Multiple Samples
@@ -3147,6 +3151,7 @@
31473151
#include "rtweekend.h"
31483152

31493153
#include "camera.h"
3154+
#include "hittable.h"
31503155
#include "hittable_list.h"
31513156
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
31523157
#include "material.h"
@@ -3412,7 +3417,7 @@
34123417
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
34133418
auto material_center = make_shared<lambertian>(color(0.1, 0.2, 0.5));
34143419
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3415-
auto material_left = make_shared<dielectric>(1.5);
3420+
auto material_left = make_shared<dielectric>(1.50);
34163421
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
34173422
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 1.0);
34183423
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -3655,9 +3660,9 @@
36553660
...
36563661
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
36573662
auto material_center = make_shared<lambertian>(color(0.1, 0.2, 0.5));
3658-
auto material_left = make_shared<dielectric>(1.50);
36593663
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
3660-
auto material_bubble = make_shared<dielectric>(0.67);
3664+
auto material_left = make_shared<dielectric>(1.50);
3665+
auto material_bubble = make_shared<dielectric>(1.00 / 1.50);
36613666
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
36623667
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 0.0);
36633668

@@ -3926,8 +3931,8 @@
39263931
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
39273932
auto material_center = make_shared<lambertian>(color(0.1, 0.2, 0.5));
39283933
auto material_left = make_shared<dielectric>(1.50);
3929-
auto material_bubble = make_shared<dielectric>(0.67);
3930-
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 0.0);
3934+
auto material_bubble = make_shared<dielectric>(1.00 / 1.50);
3935+
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 1.0);
39313936

39323937
world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground));
39333938
world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.2), 0.5, material_center));
@@ -3944,8 +3949,8 @@
39443949
cam.max_depth = 50;
39453950

39463951

3947-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
39483952
cam.vfov = 90;
3953+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
39493954
cam.lookfrom = point3(-2,2,1);
39503955
cam.lookat = point3(0,0,-1);
39513956
cam.vup = vec3(0,1,0);
@@ -4201,7 +4206,7 @@
42014206
}
42024207
};
42034208
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4204-
[Listing [camera-dof]: <kbd>[camera.h]</kbd> Camera with adjustable depth-of-field (dof)]
4209+
[Listing [camera-dof]: <kbd>[camera.h]</kbd> Camera with adjustable depth-of-field]
42054210

42064211
<div class='together'>
42074212
Using a large aperture:

books/RayTracingTheNextWeek.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279
const override {
280280
vec3 reflected = reflect(r_in.direction(), rec.normal);
281281
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
282-
scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere(), r_in.time());
282+
scattered = ray(rec.p, reflected + fuzz*random_unit_vector(), r_in.time());
283283
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
284284
attenuation = albedo;
285285
return (dot(scattered.direction(), rec.normal) > 0);

books/RayTracingTheRestOfYourLife.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3325,7 +3325,7 @@
33253325
srec.skip_pdf = true;
33263326

33273327
vec3 reflected = reflect(r_in.direction(), rec.normal);
3328-
srec.skip_pdf_ray = ray(rec.p, reflected + fuzz*random_in_unit_sphere(), r_in.time());
3328+
srec.skip_pdf_ray = ray(rec.p, reflected + fuzz*random_unit_vector(), r_in.time());
33293329

33303330
return true;
33313331
}

src/InOneWeekend/camera.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313

1414
#include "rtweekend.h"
1515

16-
#include "color.h"
1716
#include "hittable.h"
1817
#include "material.h"
1918

20-
#include <iostream>
21-
2219

2320
class camera {
2421
public:
@@ -89,7 +86,7 @@ class camera {
8986
vec3 viewport_u = viewport_width * u; // Vector across viewport horizontal edge
9087
vec3 viewport_v = viewport_height * -v; // Vector down viewport vertical edge
9188

92-
// Calculate the horizontal and vertical delta vectors to the next pixel.
89+
// Calculate the horizontal and vertical delta vectors from pixel to pixel.
9390
pixel_delta_u = viewport_u / image_width;
9491
pixel_delta_v = viewport_v / image_height;
9592

@@ -119,7 +116,7 @@ class camera {
119116
}
120117

121118
vec3 sample_square() const {
122-
// Returns a random point in the square surrounding a pixel at the origin.
119+
// Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square.
123120
return vec3(random_double() - 0.5, random_double() - 0.5, 0);
124121
}
125122

src/InOneWeekend/color.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1212
//==============================================================================================
1313

14+
#include "interval.h"
15+
#include "vec3.h"
16+
1417
using color = vec3;
1518

1619
inline double linear_to_gamma(double linear_component)

src/InOneWeekend/hittable_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class hittable_list : public hittable {
3333

3434
bool hit(const ray& r, interval ray_t, hit_record& rec) const override {
3535
hit_record temp_rec;
36-
auto hit_anything = false;
36+
bool hit_anything = false;
3737
auto closest_so_far = ray_t.max;
3838

3939
for (const auto& object : objects) {

src/InOneWeekend/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "rtweekend.h"
1313

1414
#include "camera.h"
15-
#include "color.h"
15+
#include "hittable.h"
1616
#include "hittable_list.h"
1717
#include "material.h"
1818
#include "sphere.h"

src/InOneWeekend/material.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ class metal : public material {
5757
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
5858
const override {
5959
vec3 reflected = reflect(r_in.direction(), rec.normal);
60-
scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere());
60+
scattered = ray(rec.p, reflected + fuzz*random_unit_vector());
6161
attenuation = albedo;
62-
6362
return (dot(scattered.direction(), rec.normal) > 0);
6463
}
6564

src/InOneWeekend/ray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ class ray {
3232
vec3 dir;
3333
};
3434

35+
3536
#endif

src/InOneWeekend/rtweekend.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
// C++ Std Usings
2020

21-
using std::shared_ptr;
21+
using std::fabs;
2222
using std::make_shared;
23+
using std::shared_ptr;
2324
using std::sqrt;
2425

2526
// Constants
@@ -45,6 +46,7 @@ inline double random_double(double min, double max) {
4546

4647
// Common Headers
4748

49+
#include "color.h"
4850
#include "interval.h"
4951
#include "ray.h"
5052
#include "vec3.h"

0 commit comments

Comments
 (0)