|
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 | } |
|
988 | 997 | </div> |
989 | 998 |
|
990 | 999 | <div class='together'> |
991 | | -Where you used to have |
| 1000 | +Where you used to have code like this: |
992 | 1001 |
|
993 | 1002 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
994 | 1003 | ...make_shared<lambertian>(color(0.5, 0.5, 0.5)) |
|
1001 | 1010 | ...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5)) |
1002 | 1011 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1003 | 1012 | [Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture] |
| 1013 | + |
| 1014 | +Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`. |
1004 | 1015 | </div> |
1005 | 1016 |
|
1006 | 1017 |
|
|
1041 | 1052 |
|
1042 | 1053 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1043 | 1054 | auto checker = make_shared<checker_texture>( |
1044 | | - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1055 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1056 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1045 | 1057 | ); |
1046 | 1058 |
|
1047 | 1059 | world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker))); |
|
1065 | 1077 | hittable_list objects; |
1066 | 1078 |
|
1067 | 1079 | auto checker = make_shared<checker_texture>( |
1068 | | - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1080 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1081 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1069 | 1082 | ); |
1070 | 1083 |
|
1071 | 1084 | objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker))); |
|
0 commit comments