diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d9738e4..ad1e8e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,19 @@ Change Log -- Ray Tracing in One Weekend ### _In One Weekend_ - Change: The C++ `` version of `random_double()` no longer depends on `` - header + header. + - Change: Refactored `random_scene()`. More named intermediate values, sync'ed with source. + (#489) ### _The Next Week_ + - Fix: Added clarification about updating lambertian variables from `color` to `solid_color`. + - Fix: Corrected for-loop indices (they differed from the version in book 1) in `random_scene()`. - Fix: Introduce "Texture Coordinates for Spheres" in Chapter 4 to support (u,v) coordinates in `hit_record` (#496) + - Change: Refactored `random_scene()`. More named intermediate values, sync'ed with version in + _In One Weekend_ and with source. Added highlight for update from last version in book 1. (#489) + - Change: The C++ `` version of `random_double()` no longer depends on `` + header ---------------------------------------------------------------------------------------------------- diff --git a/books/RayTracingInOneWeekend.html b/books/RayTracingInOneWeekend.html index 92239408..ebd77a1f 100644 --- a/books/RayTracingInOneWeekend.html +++ b/books/RayTracingInOneWeekend.html @@ -2846,41 +2846,45 @@ hittable_list random_scene() { hittable_list world; - world.add(make_shared( - point3(0,-1000,0), 1000, make_shared(color(0.5, 0.5, 0.5)))); + auto ground_material = make_shared(color(0.5, 0.5, 0.5)); + world.add(make_shared(point3(0,-1000,0), 1000, ground_material)); - int i = 1; for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { auto choose_mat = random_double(); point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { + shared_ptr sphere_material; + if (choose_mat < 0.8) { // diffuse auto albedo = color::random() * color::random(); - world.add( - make_shared(center, 0.2, make_shared(albedo))); + sphere_material = make_shared(albedo); + world.add(make_shared(center, 0.2, sphere_material)); } else if (choose_mat < 0.95) { // metal - auto albedo = color::random(.5, 1); - auto fuzz = random_double(0, .5); - world.add( - make_shared(center, 0.2, make_shared(albedo, fuzz))); + auto albedo = color::random(0.5, 1); + auto fuzz = random_double(0, 0.5); + sphere_material = make_shared(albedo, fuzz); + world.add(make_shared(center, 0.2, sphere_material)); } else { // glass - world.add(make_shared(center, 0.2, make_shared(1.5))); + sphere_material = make_shared(1.5); + world.add(make_shared(center, 0.2, sphere_material)); } } } } - world.add(make_shared(point3(0, 1, 0), 1.0, make_shared(1.5))); + auto material1 = make_shared(1.5); + world.add(make_shared(point3(0, 1, 0), 1.0, material1)); - world.add( - make_shared(point3(-4, 1, 0), 1.0, make_shared(color(.4, .2, .1)))); + auto material2 = make_shared(color(0.4, 0.2, 0.1)); + world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); - world.add( - make_shared(point3(4, 1, 0), 1.0, make_shared(color(.7, .6, .5), 0.0))); + auto material3 = make_shared(color(0.7, 0.6, 0.5), 0.0); + world.add(make_shared(point3(4, 1, 0), 1.0, material3)); return world; } diff --git a/books/RayTracingTheNextWeek.html b/books/RayTracingTheNextWeek.html index 1a12678c..27b9a74e 100644 --- a/books/RayTracingTheNextWeek.html +++ b/books/RayTracingTheNextWeek.html @@ -292,40 +292,49 @@ hittable_list random_scene() { hittable_list world; - world.add(make_shared( - point3(0,-1000,0), 1000, make_shared(color(0.5, 0.5, 0.5)))); + auto ground_material = make_shared(color(0.5, 0.5, 0.5)); + world.add(make_shared(point3(0,-1000,0), 1000, ground_material)); - int i = 1; - for (int a = -10; a < 10; a++) { - for (int b = -10; b < 10; b++) { + for (int a = -11; a < 11; a++) { + for (int b = -11; b < 11; b++) { auto choose_mat = random_double(); point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); - if ((center - vec3(4, .2, 0)).length() > 0.9) { + + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { + shared_ptr sphere_material; + if (choose_mat < 0.8) { // diffuse auto albedo = color::random() * color::random(); + sphere_material = make_shared(albedo); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight + auto center2 = center + vec3(0, random_double(0,.5), 0); world.add(make_shared( - center, center + vec3(0, random_double(0,.5), 0), 0.0, 1.0, 0.2, - make_shared(albedo))); + center, center2, 0.0, 1.0, 0.2, sphere_material)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ } else if (choose_mat < 0.95) { // metal - auto albedo = color::random(.5, 1); - auto fuzz = random_double(0, .5); - world.add( - make_shared(center, 0.2, make_shared(albedo, fuzz))); + auto albedo = color::random(0.5, 1); + auto fuzz = random_double(0, 0.5); + sphere_material = make_shared(albedo, fuzz); + world.add(make_shared(center, 0.2, sphere_material)); } else { // glass - world.add(make_shared(center, 0.2, make_shared(1.5))); + sphere_material = make_shared(1.5); + world.add(make_shared(center, 0.2, sphere_material)); } } } } - world.add(make_shared(point3(0, 1, 0), 1.0, make_shared(1.5))); - world.add(make_shared( - point3(-4, 1, 0), 1.0, make_shared(color(0.4, 0.2, 0.1)))); - world.add(make_shared( - point3(4, 1, 0), 1.0, make_shared(color(0.7, 0.6, 0.5), 0.0))); + auto material1 = make_shared(1.5); + world.add(make_shared(point3(0, 1, 0), 1.0, material1)); + + auto material2 = make_shared(color(0.4, 0.2, 0.1)); + world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); + + auto material3 = make_shared(color(0.7, 0.6, 0.5), 0.0); + world.add(make_shared(point3(4, 1, 0), 1.0, material3)); return world; } @@ -1053,7 +1062,7 @@
-Where you used to have +Where you used to have code like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ ...make_shared(color(0.5, 0.5, 0.5)) @@ -1066,6 +1075,8 @@ ...make_shared(make_shared(0.5, 0.5, 0.5)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [lam-textured]: [main.cc] Lambertian material with texture] + +Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`.
@@ -1106,7 +1117,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ auto checker = make_shared( - make_shared(0.2, 0.3, 0.1), make_shared(0.9, 0.9, 0.9) + make_shared(0.2, 0.3, 0.1), + make_shared(0.9, 0.9, 0.9) ); world.add(make_shared(point3(0,-1000,0), 1000, make_shared(checker))); @@ -1130,7 +1142,8 @@ hittable_list objects; auto checker = make_shared( - make_shared(0.2, 0.3, 0.1), make_shared(0.9, 0.9, 0.9) + make_shared(0.2, 0.3, 0.1), + make_shared(0.9, 0.9, 0.9) ); objects.add(make_shared(point3(0,-10, 0), 10, make_shared(checker))); diff --git a/src/InOneWeekend/main.cc b/src/InOneWeekend/main.cc index 86f271b1..eee2bda0 100644 --- a/src/InOneWeekend/main.cc +++ b/src/InOneWeekend/main.cc @@ -44,47 +44,45 @@ color ray_color(const ray& r, const hittable& world, int depth) { hittable_list random_scene() { hittable_list world; - world.add( - make_shared( - point3(0,-1000,0), 1000, make_shared(color(0.5, 0.5, 0.5))) - ); + auto ground_material = make_shared(color(0.5, 0.5, 0.5)); + world.add(make_shared(point3(0,-1000,0), 1000, ground_material)); - int i = 1; for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { auto choose_mat = random_double(); point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { + shared_ptr sphere_material; + if (choose_mat < 0.8) { // diffuse auto albedo = color::random() * color::random(); - world.add( - make_shared(center, 0.2, make_shared(albedo))); + sphere_material = make_shared(albedo); + world.add(make_shared(center, 0.2, sphere_material)); } else if (choose_mat < 0.95) { // metal - auto albedo = color::random(.5, 1); - auto fuzz = random_double(0, .5); - world.add( - make_shared(center, 0.2, make_shared(albedo, fuzz))); + auto albedo = color::random(0.5, 1); + auto fuzz = random_double(0, 0.5); + sphere_material = make_shared(albedo, fuzz); + world.add(make_shared(center, 0.2, sphere_material)); } else { // glass - world.add(make_shared(center, 0.2, make_shared(1.5))); + sphere_material = make_shared(1.5); + world.add(make_shared(center, 0.2, sphere_material)); } } } } - world.add( - make_shared( - point3(0, 1, 0), 1.0, make_shared(1.5))); + auto material1 = make_shared(1.5); + world.add(make_shared(point3(0, 1, 0), 1.0, material1)); - world.add( - make_shared( - point3(-4, 1, 0), 1.0, make_shared(color(0.4, 0.2, 0.1)))); + auto material2 = make_shared(color(0.4, 0.2, 0.1)); + world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); - world.add( - make_shared( - point3(4, 1, 0), 1.0, make_shared(color(0.7, 0.6, 0.5), 0.0))); + auto material3 = make_shared(color(0.7, 0.6, 0.5), 0.0); + world.add(make_shared(point3(4, 1, 0), 1.0, material3)); return world; } diff --git a/src/TheNextWeek/main.cc b/src/TheNextWeek/main.cc index f371c572..90d35163 100644 --- a/src/TheNextWeek/main.cc +++ b/src/TheNextWeek/main.cc @@ -57,46 +57,44 @@ hittable_list random_scene() { world.add(make_shared(point3(0,-1000,0), 1000, make_shared(checker))); - for (int a = -10; a < 10; a++) { - for (int b = -10; b < 10; b++) { + for (int a = -11; a < 11; a++) { + for (int b = -11; b < 11; b++) { auto choose_mat = random_double(); point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); - if ((center - vec3(4, .2, 0)).length() > 0.9) { + + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { + shared_ptr sphere_material; + if (choose_mat < 0.8) { // diffuse auto albedo = color::random() * color::random(); + sphere_material = make_shared(make_shared(albedo)); + auto center2 = center + vec3(0, random_double(0,.5), 0); world.add(make_shared( - center, center + vec3(0, random_double(0,.5), 0), 0.0, 1.0, 0.2, - make_shared(make_shared(albedo)) - )); + center, center2, 0.0, 1.0, 0.2, sphere_material)); } else if (choose_mat < 0.95) { // metal - auto albedo = color::random(.5, 1); - auto fuzz = random_double(0, .5); - world.add( - make_shared(center, 0.2, make_shared(albedo, fuzz))); + auto albedo = color::random(0.5, 1); + auto fuzz = random_double(0, 0.5); + sphere_material = make_shared(albedo, fuzz); + world.add(make_shared(center, 0.2, sphere_material)); } else { // glass - world.add(make_shared(center, 0.2, make_shared(1.5))); + sphere_material = make_shared(1.5); + world.add(make_shared(center, 0.2, sphere_material)); } } } } - world.add(make_shared(point3(0,1,0), 1.0, make_shared(1.5))); + auto material1 = make_shared(1.5); + world.add(make_shared(point3(0, 1, 0), 1.0, material1)); - world.add( - make_shared( - point3(-4,1,0), 1.0, - make_shared(make_shared(0.4, 0.2, 0.1)) - ) - ); + auto material2 = make_shared(make_shared(color(0.4, 0.2, 0.1))); + world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); - world.add( - make_shared( - point3(4,1,0), 1.0, make_shared(color(0.7, 0.6, 0.5), 0.0) - ) - ); + auto material3 = make_shared(color(0.7, 0.6, 0.5), 0.0); + world.add(make_shared(point3(4, 1, 0), 1.0, material3)); return hittable_list(make_shared(world, 0.0, 1.0)); } @@ -106,7 +104,8 @@ hittable_list two_spheres() { hittable_list objects; auto checker = make_shared( - make_shared(0.2, 0.3, 0.1), make_shared(0.9, 0.9, 0.9) + make_shared(0.2, 0.3, 0.1), + make_shared(0.9, 0.9, 0.9) ); objects.add(make_shared(point3(0,-10, 0), 10, make_shared(checker)));