Lighting in Shadows

Given some point, you can know that it lies in shadow if there is another object sitting between it and the light source, as shown in the following figure.

images/shadows/shadow-definition.png

The light source is unable to contribute anything to that point. Take a moment and recall how your lighting function works, from The Phong Reflection Model. The diffuse component relies on the vector to the light source, and the specular component depends on the reflection vector. Since both components have a dependency on the light source, the lighting function should ignore them when the point is in shadow and use only the ambient component.

Add the following test to the others you wrote for the lighting function. It’s identical to the one titled “Lighting with the eye between the light and the surface”, where the specular and diffuse components were both at their maximum values, but this time you’re going to pass a new argument to the lighting function indicating that the point is in shadow. It should cause the diffuse and specular components to be ignored, resulting in the ambient value alone contributing to the lighting.

(Recall that the m and position variables being passed to the lighting function are defined in the “Background” block.)

 Scenario​: Lighting with the surface in shadow
 Given​ eyev ← vector(0, 0, -1)
 And​ normalv ← vector(0, 0, -1)
 And​ light ← point_light(point(0, 0, -10), color(1, 1, 1))
 And​ in_shadow ← true
 When​ result ← lighting(m, light, position, eyev, normalv, in_shadow)
 Then​ result = color(0.1, 0.1, 0.1)

You may need to fix your other tests to accommodate the addition of that new parameter. Go ahead and address that, and then make this new test pass as well by making your lighting function ignore the specular and diffuse components when in_shadow is true.

Once things are all passing again, let’s teach your ray tracer how to tell when a point is in shadow.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.6.194