View on GitHub

Cardinal3D

Stanford CS248A (Assignments 2 and 3)

(Task 4) Shadow Rays

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

Currently Pathtracer::trace_ray computes the following:

Shadows occur when another scene object blocks light emitted from scene light sources towards the hit point. 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.position), and traveling towards the light source (direction to light) hits any scene geometry before reaching the light.

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

At this point you should be able to render very striking images with shadows.

Sample results:

At this point, you can add all kinds of lights using “New Light” in Layout mode, except for Sphere Light and Environment Map which you have the option to implement later (Note that you can still fill in Sphere::Uniform::sample in Samplers.cpp now to view the result of a mesh under Sphere Light). Here are some examples:

A sphere and a cube with hemishphere lighting

shadow_hemisphere

Hex and cube under diretional lighting

ref1

Bunny on a plane under point light

ref1

Spot on a sphere under diretional lighting

ref1

Spot on a sphere under hemisphere lighting

ref1