Lab 20

After this class you will be able to implement the specular component in the phong reflection model and a simple algorithm that produces shadows.

Specular Reflection

TODO: Extend the lighting calculations with the specular parts of the Phong model.

I will explain the math in class

In contrast to what your book teaches and what I said in class you have to test whether: (R * V) < 0.0 and NOT whether (R * V)^alpha < 0. Use the exponent after you have done that test. Pictures were updated to reflect this below.

Your image should look similar to this:

Shadows

TODO:

  • add another sphere to your scene file
    • Material: gray; color: 0.6, ambient 0.2, diffuse 0.8, phong 0, phong_size 1
    • Sphere: center 200 200 -1000, radius 1000
  • Extend the lighting calculation in Raytracer::trace(Ray) such that it produces shadows. To achieve this you should test whether a ray from the light source to the object intersects other objects. Only when this not the case, the light source contributes to the lighting.

How this can be done will be explained in class

Your image should look similar to this:

TODO: Test that your lighting calculations work correctly for several light sources. The following image was created with two lights:

=cpp light { location -200 600 1500 color 0.4 0.4 0.8 } light { location 600 600 1500 color 0.8 0.8 0.4 }

Spotlights

Now that you have multiple lights and shadows, spotlights are extremely easy to implement. Read Section 6.2.4 in your book and look at the POVRay documentation on spotlights. To get started you can ignore the tightness value and just implement a linear falloff. The following picture has been created with these settings, the spheres from test.sdl and the lights as set below.

=cpp light { location 600 200 1500 radius 2 falloff 7 point_at 200 200 200 color 1 1 1 } light { location -200 600 1500 radius 1 falloff 5 point_at 200 200 200 color 0.4 0.4 0.8 } light { location 600 600 1500 color 0.8 0.8 0.4 radius 3 falloff 9 point_at 200 200 200 }