File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -24,15 +24,18 @@ class scene {
2424
2525 std::cout << " P3\n " << image_width << ' ' << image_height << " \n 255\n " ;
2626
27+ int sqrt_spp = int (sqrt (samples_per_pixel));
2728 for (int j = image_height-1 ; j >= 0 ; --j) {
2829 std::clog << " \r Scanlines remaining: " << j << ' ' << std::flush;
2930 for (int i = 0 ; i < image_width; ++i) {
3031 color pixel_color (0 ,0 ,0 );
31- for (int sample = 0 ; sample < samples_per_pixel; ++sample) {
32- auto u = (i + random_double ()) / (image_width-1 );
33- auto v = (j + random_double ()) / (image_height-1 );
34- ray r = cam.get_ray (u, v);
35- pixel_color += ray_color (r, max_depth);
32+ for (int s_j = 0 ; s_j < sqrt_spp; ++s_j) {
33+ for (int s_i = 0 ; s_i < sqrt_spp; ++s_i) {
34+ auto u = (i + (s_i + random_double ()) / sqrt_spp) / (image_width-1 );
35+ auto v = (j + (s_j + random_double ()) / sqrt_spp) / (image_height-1 );
36+ ray r = cam.get_ray (u, v);
37+ pixel_color += ray_color (r, max_depth);
38+ }
3639 }
3740 write_color (std::cout, pixel_color, samples_per_pixel);
3841 }
You can’t perform that action at this time.
0 commit comments