|
140 | 140 | private:
|
141 | 141 | ...
|
142 | 142 | ray get_ray(int i, int j) const {
|
143 |
| - auto s = (i + random_double()) / (image_width - 1); |
144 |
| - auto t = (j + random_double()) / (image_height - 1); |
| 143 | + // Get a randomly-sampled camera ray for the pixel at location i,j, originating from |
| 144 | + // the camera defocus disk. |
145 | 145 |
|
146 |
| - vec3 rd = lens_radius * random_in_unit_disk(); |
147 |
| - vec3 offset = u * rd.x() + v * rd.y(); |
148 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
149 |
| - auto ray_time = random_double(0.0, 1.0); |
150 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 146 | + auto pixel_center = pixel00_loc + (i * pixel_delta_u) + (j * pixel_delta_v); |
| 147 | + auto pixel_sample = pixel_center + pixel_sample_square(); |
151 | 148 |
|
152 |
| - return ray( |
153 |
| - origin + offset, |
| 149 | + auto ray_origin = (defocus_angle <= 0) ? center : defocus_disk_sample(); |
| 150 | + auto ray_direction = pixel_sample - ray_origin; |
154 | 151 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
155 |
| - lower_left_corner + s*horizontal + (1-t)*vertical - origin - offset, |
156 |
| - ray_time |
| 152 | + auto ray_time = random_double(); |
| 153 | + |
| 154 | + return ray(ray_origin, ray_direction, ray_time); |
157 | 155 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
158 |
| - ); |
159 | 156 | }
|
160 | 157 |
|
161 | 158 | ...
|
|
364 | 361 | cam.lookat = point3(0,0,0);
|
365 | 362 | cam.vup = vec3(0,1,0);
|
366 | 363 |
|
367 |
| - cam.aperture = 0.1; |
368 |
| - cam.focus_dist = 10.0; |
| 364 | + cam.defocus_angle = 0.02; |
| 365 | + cam.focus_dist = 10.0; |
369 | 366 |
|
370 | 367 | cam.render(world);
|
371 | 368 | }
|
|
1281 | 1278 | ...
|
1282 | 1279 | }
|
1283 | 1280 |
|
| 1281 | + |
1284 | 1282 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1285 | 1283 | void two_spheres() {
|
1286 | 1284 | hittable_list world;
|
|
1296 | 1294 | cam.image_width = 400;
|
1297 | 1295 | cam.samples_per_pixel = 100;
|
1298 | 1296 | cam.max_depth = 50;
|
1299 |
| - cam.background = color(0.70, 0.80, 1.00); |
1300 | 1297 |
|
| 1298 | + cam.vfov = 20; |
1301 | 1299 | cam.lookfrom = point3(13,2,3);
|
1302 | 1300 | cam.lookat = point3(0,0,0);
|
1303 | 1301 | cam.vup = vec3(0,1,0);
|
1304 |
| - cam.vfov = 20; |
1305 | 1302 |
|
1306 |
| - cam.aperture = 0; |
| 1303 | + cam.defocus_angle = 0; |
1307 | 1304 |
|
1308 | 1305 | cam.render(world);
|
1309 | 1306 | }
|
|
1672 | 1669 | cam.image_width = 400;
|
1673 | 1670 | cam.samples_per_pixel = 100;
|
1674 | 1671 | cam.max_depth = 50;
|
1675 |
| - cam.background = color(0.70, 0.80, 1.00); |
1676 | 1672 |
|
| 1673 | + cam.vfov = 20; |
1677 | 1674 | cam.lookfrom = point3(0,0,12);
|
1678 | 1675 | cam.lookat = point3(0,0,0);
|
1679 | 1676 | cam.vup = vec3(0,1,0);
|
1680 |
| - cam.vfov = 20; |
1681 | 1677 |
|
1682 |
| - cam.aperture = 0; |
| 1678 | + cam.defocus_angle = 0; |
1683 | 1679 |
|
1684 | 1680 | cam.render(hittable_list(globe));
|
1685 | 1681 | }
|
|
1853 | 1849 | cam.image_width = 400;
|
1854 | 1850 | cam.samples_per_pixel = 100;
|
1855 | 1851 | cam.max_depth = 50;
|
1856 |
| - cam.background = color(0.70, 0.80, 1.00); |
1857 | 1852 |
|
| 1853 | + cam.vfov = 20; |
1858 | 1854 | cam.lookfrom = point3(13,2,3);
|
1859 | 1855 | cam.lookat = point3(0,0,0);
|
1860 | 1856 | cam.vup = vec3(0,1,0);
|
1861 |
| - cam.vfov = 20; |
1862 | 1857 |
|
1863 |
| - cam.aperture = 0; |
| 1858 | + cam.defocus_angle = 0; |
1864 | 1859 |
|
1865 | 1860 | cam.render(world);
|
1866 | 1861 | }
|
|
2839 | 2834 | cam.image_width = 400;
|
2840 | 2835 | cam.samples_per_pixel = 100;
|
2841 | 2836 | cam.max_depth = 50;
|
2842 |
| - cam.background = color(0.70, 0.80, 1.00); |
2843 | 2837 |
|
| 2838 | + cam.vfov = 80; |
2844 | 2839 | cam.lookfrom = point3(0,0,9);
|
2845 | 2840 | cam.lookat = point3(0,0,0);
|
2846 | 2841 | cam.vup = vec3(0,1,0);
|
2847 |
| - cam.vfov = 80; |
2848 | 2842 |
|
2849 |
| - cam.aperture = 0; |
| 2843 | + cam.defocus_angle = 0; |
2850 | 2844 |
|
2851 | 2845 | cam.render(world);
|
2852 | 2846 | }
|
|
2943 | 2937 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2944 | 2938 | class camera {
|
2945 | 2939 | public:
|
2946 |
| - double aspect_ratio = 1.0; |
2947 |
| - int image_width = 100; |
2948 |
| - int samples_per_pixel = 10; |
2949 |
| - int max_depth = 10; |
| 2940 | + double aspect_ratio = 1.0; // Ratio of image width over height |
| 2941 | + int image_width = 100; // Rendered image width in pixel count |
| 2942 | + int samples_per_pixel = 10; // Count of random samples for each pixel |
| 2943 | + int max_depth = 10; // Maximum number of ray bounces into scene |
2950 | 2944 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2951 |
| - color background = color(0,0,0); |
| 2945 | + color background; // Scene background color |
2952 | 2946 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2953 | 2947 |
|
2954 |
| - double vfov = 40; |
2955 | 2948 | ...
|
2956 | 2949 |
|
2957 | 2950 | private:
|
|
3087 | 3080 |
|
3088 | 3081 | camera cam;
|
3089 | 3082 |
|
3090 |
| - cam.image_width = 400; |
3091 | 3083 | cam.aspect_ratio = 16.0 / 9.0;
|
| 3084 | + cam.image_width = 400; |
3092 | 3085 | cam.samples_per_pixel = 100;
|
3093 | 3086 | cam.max_depth = 50;
|
3094 | 3087 | cam.background = color(0,0,0);
|
3095 | 3088 |
|
| 3089 | + cam.vfov = 20; |
3096 | 3090 | cam.lookfrom = point3(26,3,6);
|
3097 | 3091 | cam.lookat = point3(0,2,0);
|
3098 | 3092 | cam.vup = vec3(0,1,0);
|
3099 |
| - cam.vfov = 20; |
3100 | 3093 |
|
3101 |
| - cam.aperture = 0; |
| 3094 | + cam.defocus_angle = 0; |
3102 | 3095 |
|
3103 | 3096 | cam.render(world);
|
3104 | 3097 | }
|
|
3179 | 3172 | cam.max_depth = 50;
|
3180 | 3173 | cam.background = color(0,0,0);
|
3181 | 3174 |
|
| 3175 | + cam.vfov = 40; |
3182 | 3176 | cam.lookfrom = point3(278, 278, -800);
|
3183 | 3177 | cam.lookat = point3(278, 278, 0);
|
3184 | 3178 | cam.vup = vec3(0,1,0);
|
3185 |
| - cam.vfov = 40; |
3186 | 3179 |
|
3187 |
| - cam.aperture = 0; |
| 3180 | + cam.defocus_angle = 0; |
3188 | 3181 |
|
3189 | 3182 | cam.render(world);
|
3190 | 3183 | }
|
|
3828 | 3821 | cam.max_depth = 50;
|
3829 | 3822 | cam.background = color(0,0,0);
|
3830 | 3823 |
|
| 3824 | + cam.vfov = 40; |
3831 | 3825 | cam.lookfrom = point3(278, 278, -800);
|
3832 | 3826 | cam.lookat = point3(278, 278, 0);
|
3833 | 3827 | cam.vup = vec3(0,1,0);
|
3834 |
| - cam.vfov = 40; |
3835 | 3828 |
|
3836 |
| - cam.aperture = 0; |
| 3829 | + cam.defocus_angle = 0; |
3837 | 3830 |
|
3838 | 3831 | cam.render(world);
|
3839 | 3832 | }
|
|
3953 | 3946 | cam.max_depth = max_depth;
|
3954 | 3947 | cam.background = color(0,0,0);
|
3955 | 3948 |
|
| 3949 | + cam.vfov = 40; |
3956 | 3950 | cam.lookfrom = point3(478, 278, -600);
|
3957 | 3951 | cam.lookat = point3(278, 278, 0);
|
3958 | 3952 | cam.vup = vec3(0,1,0);
|
3959 |
| - cam.vfov = 40; |
3960 | 3953 |
|
3961 |
| - cam.aperture = 0; |
| 3954 | + cam.defocus_angle = 0; |
3962 | 3955 |
|
3963 | 3956 | cam.render(world);
|
3964 | 3957 | }
|
|
0 commit comments