|
292 | 292 | hittable_list random_scene() { |
293 | 293 | hittable_list world; |
294 | 294 |
|
295 | | - world.add(make_shared<sphere>( |
296 | | - point3(0,-1000,0), 1000, make_shared<lambertian>(color(0.5, 0.5, 0.5)))); |
| 295 | + auto ground_material = make_shared<lambertian>(color(0.5, 0.5, 0.5)); |
| 296 | + world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material)); |
297 | 297 |
|
298 | | - int i = 1; |
299 | | - for (int a = -10; a < 10; a++) { |
300 | | - for (int b = -10; b < 10; b++) { |
| 298 | + for (int a = -11; a < 11; a++) { |
| 299 | + for (int b = -11; b < 11; b++) { |
301 | 300 | auto choose_mat = random_double(); |
302 | 301 | point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double()); |
303 | | - if ((center - vec3(4, .2, 0)).length() > 0.9) { |
| 302 | + |
| 303 | + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { |
| 304 | + shared_ptr<material> sphere_material; |
| 305 | + |
304 | 306 | if (choose_mat < 0.8) { |
305 | 307 | // diffuse |
306 | 308 | auto albedo = color::random() * color::random(); |
| 309 | + sphere_material = make_shared<lambertian>(albedo); |
| 310 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 311 | + auto center2 = center + vec3(0, random_double(0,.5), 0); |
307 | 312 | 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))); |
| 313 | + center, center2, 0.0, 1.0, 0.2, sphere_material)); |
| 314 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
310 | 315 | } else if (choose_mat < 0.95) { |
311 | 316 | // 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))); |
| 317 | + auto albedo = color::random(0.5, 1); |
| 318 | + auto fuzz = random_double(0, 0.5); |
| 319 | + sphere_material = make_shared<metal>(albedo, fuzz); |
| 320 | + world.add(make_shared<sphere>(center, 0.2, sphere_material)); |
316 | 321 | } else { |
317 | 322 | // glass |
318 | | - world.add(make_shared<sphere>(center, 0.2, make_shared<dielectric>(1.5))); |
| 323 | + sphere_material = make_shared<dielectric>(1.5); |
| 324 | + world.add(make_shared<sphere>(center, 0.2, sphere_material)); |
319 | 325 | } |
320 | 326 | } |
321 | 327 | } |
322 | 328 | } |
323 | 329 |
|
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))); |
| 330 | + auto material1 = make_shared<dielectric>(1.5); |
| 331 | + world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1)); |
| 332 | + |
| 333 | + auto material2 = make_shared<lambertian>(color(0.4, 0.2, 0.1)); |
| 334 | + world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2)); |
| 335 | + |
| 336 | + auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0); |
| 337 | + world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3)); |
329 | 338 |
|
330 | 339 | return world; |
331 | 340 | } |
|
1053 | 1062 | </div> |
1054 | 1063 |
|
1055 | 1064 | <div class='together'> |
1056 | | -Where you used to have |
| 1065 | +Where you used to have code like this: |
1057 | 1066 |
|
1058 | 1067 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1059 | 1068 | ...make_shared<lambertian>(color(0.5, 0.5, 0.5)) |
|
1066 | 1075 | ...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5)) |
1067 | 1076 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1068 | 1077 | [Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture] |
| 1078 | + |
| 1079 | +Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`. |
1069 | 1080 | </div> |
1070 | 1081 |
|
1071 | 1082 |
|
|
1106 | 1117 |
|
1107 | 1118 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1108 | 1119 | auto checker = make_shared<checker_texture>( |
1109 | | - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1120 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1121 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1110 | 1122 | ); |
1111 | 1123 |
|
1112 | 1124 | world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker))); |
|
1130 | 1142 | hittable_list objects; |
1131 | 1143 |
|
1132 | 1144 | auto checker = make_shared<checker_texture>( |
1133 | | - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1145 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1146 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1134 | 1147 | ); |
1135 | 1148 |
|
1136 | 1149 | objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker))); |
|
0 commit comments