23
23
#include < iostream>
24
24
25
25
26
- vec3 ray_color (const ray& r, hittable& world, int depth) {
26
+ vec3 ray_color (const ray& r, hittable& world, const vec3& background, int depth) {
27
27
hit_record rec;
28
28
29
29
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -32,7 +32,7 @@ vec3 ray_color(const ray& r, hittable& world, int depth) {
32
32
33
33
// If the ray hits nothing, return the background color.
34
34
if (!world.hit (r, 0.001 , infinity, rec))
35
- return vec3 ( 0.5 , 0.5 , 0.5 ) ;
35
+ return background ;
36
36
37
37
ray scattered;
38
38
vec3 attenuation;
@@ -41,7 +41,7 @@ vec3 ray_color(const ray& r, hittable& world, int depth) {
41
41
if (!rec.mat_ptr ->scatter (r, rec, attenuation, scattered))
42
42
return emitted;
43
43
44
- return emitted + attenuation * ray_color (scattered, world, depth-1 );
44
+ return emitted + attenuation * ray_color (scattered, world, background, depth-1 );
45
45
}
46
46
47
47
@@ -360,34 +360,39 @@ int main() {
360
360
auto vfov = 40.0 ;
361
361
auto aperture = 0.0 ;
362
362
auto dist_to_focus = 10.0 ;
363
+ vec3 background (0 ,0 ,0 );
363
364
364
365
switch (0 ) {
365
366
case 1 :
366
367
world = random_scene ();
367
368
lookfrom = vec3 (13 ,2 ,3 );
368
369
lookat = vec3 (0 ,0 ,0 );
369
370
vfov = 20.0 ;
371
+ background = vec3 (0.70 , 0.80 , 1.00 );
370
372
break ;
371
373
372
374
case 2 :
373
375
world = two_spheres ();
374
376
lookfrom = vec3 (13 ,2 ,3 );
375
377
lookat = vec3 (0 ,0 ,0 );
376
378
vfov = 20.0 ;
379
+ background = vec3 (0.70 , 0.80 , 1.00 );
377
380
break ;
378
381
379
382
case 3 :
380
383
world = two_perlin_spheres ();
381
384
lookfrom = vec3 (13 ,2 ,3 );
382
385
lookat = vec3 (0 ,0 ,0 );
383
386
vfov = 20.0 ;
387
+ background = vec3 (0.70 , 0.80 , 1.00 );
384
388
break ;
385
389
386
390
case 4 :
387
391
world = earth ();
388
392
lookfrom = vec3 (0 ,0 ,12 );
389
393
lookat = vec3 (0 ,0 ,0 );
390
394
vfov = 20.0 ;
395
+ background = vec3 (0.70 , 0.80 , 1.00 );
391
396
break ;
392
397
393
398
case 5 :
@@ -446,7 +451,7 @@ int main() {
446
451
auto u = (i + random_double ()) / image_width;
447
452
auto v = (j + random_double ()) / image_height;
448
453
ray r = cam.get_ray (u, v);
449
- color += ray_color (r, world, max_depth);
454
+ color += ray_color (r, world, background, max_depth);
450
455
}
451
456
color.write_color (std::cout, samples_per_pixel);
452
457
}
0 commit comments