|
7 | 7 | Peter Shirley
|
8 | 8 | edited by Steve Hollasch and Trevor David Black
|
9 | 9 | <br>
|
10 |
| - Version 3.1.0, 2020-05-03 |
| 10 | + Version 3.1.1, 2020-05-16 |
11 | 11 | <br>
|
12 | 12 | Copyright 2018-2020 Peter Shirley. All rights reserved.
|
13 | 13 |
|
|
108 | 108 | class camera {
|
109 | 109 | public:
|
110 | 110 | camera(
|
111 |
| - point3 lookfrom, point3 lookat, vec3 vup, |
| 111 | + point3 lookfrom, |
| 112 | + point3 lookat, |
| 113 | + vec3 vup, |
112 | 114 | double vfov, // vertical field-of-view in degrees
|
113 |
| - double aspect_ratio, double aperture, double focus_dist, |
| 115 | + double aspect_ratio, |
| 116 | + double aperture, |
| 117 | + double focus_dist, |
114 | 118 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
115 |
| - double t0 = 0, double t1 = 0 |
| 119 | + double t0 = 0, |
| 120 | + double t1 = 0 |
116 | 121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
117 | 122 | ) {
|
118 |
| - origin = lookfrom; |
119 |
| - lens_radius = aperture / 2; |
120 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
121 |
| - time0 = t0; |
122 |
| - time1 = t1; |
123 |
| - |
124 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
125 | 123 | auto theta = degrees_to_radians(vfov);
|
126 |
| - auto half_height = tan(theta/2); |
127 |
| - auto half_width = aspect * half_height; |
| 124 | + auto h = tan(theta/2); |
| 125 | + auto viewport_height = 2.0 * h; |
| 126 | + auto viewport_width = aspect_ratio * viewport_height; |
128 | 127 |
|
129 | 128 | w = unit_vector(lookfrom - lookat);
|
130 | 129 | u = unit_vector(cross(vup, w));
|
131 | 130 | v = cross(w, u);
|
132 | 131 |
|
133 |
| - lower_left_corner = origin |
134 |
| - - half_width*focus_dist*u |
135 |
| - - half_height*focus_dist*v |
136 |
| - - focus_dist*w; |
| 132 | + origin = lookfrom; |
| 133 | + horizontal = focus_dist * viewport_width * u; |
| 134 | + vertical = focus_dist * viewport_height * v; |
| 135 | + lower_left_corner = origin - horizontal/2 - vertical/2 - focus_dist*w; |
137 | 136 |
|
138 |
| - horizontal = 2*half_width*focus_dist*u; |
139 |
| - vertical = 2*half_height*focus_dist*v; |
| 137 | + lens_radius = aperture / 2; |
| 138 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 139 | + time0 = t0; |
| 140 | + time1 = t1; |
| 141 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
140 | 142 | }
|
141 | 143 |
|
142 | 144 | ray get_ray(double s, double t) const {
|
|
292 | 294 | hittable_list random_scene() {
|
293 | 295 | hittable_list world;
|
294 | 296 |
|
295 |
| - world.add(make_shared<sphere>( |
296 |
| - point3(0,-1000,0), 1000, make_shared<lambertian>(color(0.5, 0.5, 0.5)))); |
| 297 | + auto ground_material = make_shared<lambertian>(color(0.5, 0.5, 0.5)); |
| 298 | + world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material)); |
297 | 299 |
|
298 |
| - int i = 1; |
299 |
| - for (int a = -10; a < 10; a++) { |
300 |
| - for (int b = -10; b < 10; b++) { |
| 300 | + for (int a = -11; a < 11; a++) { |
| 301 | + for (int b = -11; b < 11; b++) { |
301 | 302 | auto choose_mat = random_double();
|
302 | 303 | point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
|
303 |
| - if ((center - vec3(4, .2, 0)).length() > 0.9) { |
| 304 | + |
| 305 | + if ((center - vec3(4, 0.2, 0)).length() > 0.9) { |
| 306 | + shared_ptr<material> sphere_material; |
| 307 | + |
304 | 308 | if (choose_mat < 0.8) {
|
305 | 309 | // diffuse
|
306 | 310 | auto albedo = color::random() * color::random();
|
| 311 | + sphere_material = make_shared<lambertian>(albedo); |
| 312 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 313 | + auto center2 = center + vec3(0, random_double(0,.5), 0); |
307 | 314 | 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))); |
| 315 | + center, center2, 0.0, 1.0, 0.2, sphere_material)); |
| 316 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
310 | 317 | } else if (choose_mat < 0.95) {
|
311 | 318 | // 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))); |
| 319 | + auto albedo = color::random(0.5, 1); |
| 320 | + auto fuzz = random_double(0, 0.5); |
| 321 | + sphere_material = make_shared<metal>(albedo, fuzz); |
| 322 | + world.add(make_shared<sphere>(center, 0.2, sphere_material)); |
316 | 323 | } else {
|
317 | 324 | // glass
|
318 |
| - world.add(make_shared<sphere>(center, 0.2, make_shared<dielectric>(1.5))); |
| 325 | + sphere_material = make_shared<dielectric>(1.5); |
| 326 | + world.add(make_shared<sphere>(center, 0.2, sphere_material)); |
319 | 327 | }
|
320 | 328 | }
|
321 | 329 | }
|
322 | 330 | }
|
323 | 331 |
|
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))); |
| 332 | + auto material1 = make_shared<dielectric>(1.5); |
| 333 | + world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1)); |
| 334 | + |
| 335 | + auto material2 = make_shared<lambertian>(color(0.4, 0.2, 0.1)); |
| 336 | + world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2)); |
| 337 | + |
| 338 | + auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0); |
| 339 | + world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3)); |
329 | 340 |
|
330 | 341 | return world;
|
331 | 342 | }
|
|
802 | 813 | list along one axis. I’ll go for simplicity:
|
803 | 814 |
|
804 | 815 | 1. randomly choose an axis
|
805 |
| - 2. sort the primitives using library qsort |
| 816 | + 2. sort the primitives (`using std::sort`) |
806 | 817 | 3. put half in each subtree
|
807 | 818 |
|
808 | 819 | </div>
|
|
1054 | 1065 | </div>
|
1055 | 1066 |
|
1056 | 1067 | <div class='together'>
|
1057 |
| -Where you used to have |
| 1068 | +Where you used to have code like this: |
1058 | 1069 |
|
1059 | 1070 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1060 | 1071 | ...make_shared<lambertian>(color(0.5, 0.5, 0.5))
|
|
1067 | 1078 | ...make_shared<lambertian>(make_shared<solid_color>(0.5, 0.5, 0.5))
|
1068 | 1079 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1069 | 1080 | [Listing [lam-textured]: <kbd>[main.cc]</kbd> Lambertian material with texture]
|
| 1081 | + |
| 1082 | +Update all three occurrences of lambertian in the `random_scene()` function in `main.cc`. |
1070 | 1083 | </div>
|
1071 | 1084 |
|
1072 | 1085 |
|
|
1107 | 1120 |
|
1108 | 1121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1109 | 1122 | auto checker = make_shared<checker_texture>(
|
1110 |
| - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1123 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1124 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1111 | 1125 | );
|
1112 | 1126 |
|
1113 | 1127 | world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker)));
|
|
1131 | 1145 | hittable_list objects;
|
1132 | 1146 |
|
1133 | 1147 | auto checker = make_shared<checker_texture>(
|
1134 |
| - make_shared<solid_color>(0.2, 0.3, 0.1), make_shared<solid_color>(0.9, 0.9, 0.9) |
| 1148 | + make_shared<solid_color>(0.2, 0.3, 0.1), |
| 1149 | + make_shared<solid_color>(0.9, 0.9, 0.9) |
1135 | 1150 | );
|
1136 | 1151 |
|
1137 | 1152 | objects.add(make_shared<sphere>(point3(0,-10, 0), 10, make_shared<lambertian>(checker)));
|
|
0 commit comments