Return Black if max depth exceeded
This commit is contained in:
parent
4eafa294ed
commit
90530b74ef
1 changed files with 12 additions and 0 deletions
12
src/scene.cc
12
src/scene.cc
|
|
@ -179,6 +179,10 @@ Scene::add_light(PointLight *light)
|
||||||
Color
|
Color
|
||||||
Scene::trace_ray(const Ray &ray, const int depth)
|
Scene::trace_ray(const Ray &ray, const int depth)
|
||||||
{
|
{
|
||||||
|
if (depth >= max_depth) {
|
||||||
|
return Color::Black;
|
||||||
|
}
|
||||||
|
|
||||||
Color out_color = Color::Black;
|
Color out_color = Color::Black;
|
||||||
Shape *intersected_shape = NULL;
|
Shape *intersected_shape = NULL;
|
||||||
float *t = NULL;
|
float *t = NULL;
|
||||||
|
|
@ -207,6 +211,10 @@ Scene::trace_ray(const Ray &ray, const int depth)
|
||||||
return out_color;
|
return out_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Diffuse lighting. (Shading, etc.)
|
||||||
|
*/
|
||||||
|
|
||||||
Material shape_material = intersected_shape->get_material();
|
Material shape_material = intersected_shape->get_material();
|
||||||
Color shape_color = shape_material.get_diffuse_color();
|
Color shape_color = shape_material.get_diffuse_color();
|
||||||
|
|
||||||
|
|
@ -245,5 +253,9 @@ Scene::trace_ray(const Ray &ray, const int depth)
|
||||||
+ diffuse_level * ldotn);
|
+ diffuse_level * ldotn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Specular lighting. (Reflections, etc.)
|
||||||
|
*/
|
||||||
|
|
||||||
return out_color;
|
return out_color;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue