I am currently reading through Peter Shirley's Ray Tracing in One Weekend. In the beginning chapters where the author introduces diffuse surfaces we a presented with this function:
vec3 color(const ray& r, hitable *world)
{
hit_record rec;
if(world->hit(r, 0.0, MAXFLOAT,rec))
{
vec3 target = rec.p + rec.normal + random_in_unit_sphere();
return 0.5*color(ray(rec.p, target-rec.p), world);
}
else
{
vec3 unit_direction = unit_vector(r.direction());
float t = 0.5*(unit_direction.y() + 1.0);
return (1.0-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0);
}
}
Can somebody where the actual definition for the function is? Because in the first part of the if
the return value
is 0.5*color(ray(rec.p, target-rec.p), world);
. Will it execute the function again except go through the else
?
Regarding what the function actually does here is what I have gathered from the book based on my current understanding:
- Pick a random point s from the unit radius sphere that is tangent to the hitpoint, and send a ray from the hitpoint p to the random point s. That sphere has center (p+N)
- Which then gives us: