Project 4: Rendering shadows


In this project, we will cast shadow rays from the points of intersection when calculating the Phong shading.

Three spheres of three different colors. The middle one has a shadow cast by the right one.

The sphere in the middle has a shadowed area due to the right sphere blocking some of the light.

Cast shadow rays at each intersection point

Whenever a ray intersects an object at point a point `vec bbp`, loop through each light in the scene and construct a new ray with the following parameters:

These are the shadow rays.

Determine if a sphere is in shadow from a light

For each shadow ray, loop through all the objects in the scene except the current one (the one with the interesection we're trying to shade). If the shadow ray intersects any of these objects with `0 < t < 1`, the original intersection point is in shadow from the corresponding light.

If a point on a sphere is in shadow from a particular light, don't include the diffuse and specular terms of the Phong illumination model for that light. Continue including contributions from any lights that are not blocked by other objects.