(Task 4) Shadow Rays - cmu462/Scotty3D GitHub Wiki

In this task you will modify Pathtracer::trace_ray() to implement accurate shadows.

Currently trace_ray computes the following:

  • It computes the intersection of ray r with the scene.
  • It computes the amount of light arriving at the hit point hit_p (the irradiance at the hit point) by integrating radiance from all scene light sources.
  • It computes the radiance reflected from the hit_p in the direction of -r. (The amount of reflected light is based on the BSDF of the surface at the hit point.)

Shadows occur when another scene object blocks light emitted from scene light sources towards the hit point (hit_p). Fortunately, determining whether or not a ray of light from a light source to the hit point is occluded by another object is easy given a working ray tracer (which you have at this point!). You simply want to know whether a ray originating from the hit point (hit_p), and traveling towards the light source (dir_to_light) hits any scene geometry before reaching the light. (Note that the light's distance from the hit point is given by dist_to_light.)

Your job is to implement the logic needed to compute whether hit_p is in shadow with respect to the current light source sample. Below are a few tips:

  • A common ray tracing pitfall is for the "shadow ray" shot into the scene to accidentally hit the same triangle as r (the surface is erroneously determined to be occluded because the shadow ray is determined to hit the surface!). We recommend that you make sure the origin of the shadow ray is offset from the surface to avoid these erroneous "self-intersections". For example, o = hit_p + epsilon * dir_to_light (note: EPS_D is defined for this purpose).
  • Another common pitfall is forgetting that it doesn't matter if the shadow ray hits any scene geometry after reaching the light. Note that the light's distance from the hit point is given by dist_to_light. Also note that Ray has a member called max_t...
  • You will find it useful to debug your shadow code using the DirectionalLight since it produces hard shadows that are easy to reason about.

At this point you should be able to render very striking images. For example, here is the Stanford Dragon model rendered with both a directional light (light coming from a single direction only) and a hemispherical light (light coming from all directions). Notice how both have realistic shadows in response to the the lighting conditions.

width=600px

width=600px