Lab 19 - Phong Shading I
After this class you will be able to calculate normals for the sphere and implement ambient and diffuse lighting for the raytracer.
Todo
- To accomodate Pavol Federl's new scene description files, the framework was changed
- If you are in my Lab2 save your intersect code from the sphere class (don't overwrite it)
- Download the new framework
- Extract the framework into a new folder
- Change the image size in test.sdl to 400 400
- Try to compile the new framework and run it ./ray test.sdl
- Lab1: Browse to the sphere.cpp class. We will implement ray-sphere intersection there
- Lab2: Copy the intersection code to the new sphere.cpp file and make sure it compiles and the output image is still the same
- If you want to see a "progress" output during the raytracing include the following line "if (row % 4 == 0) cerr << row * 100 / (height-1) << "%\r"; " in Raytracer::trace(ImageLib::ImageRGB &img) after the first for loop ''for(int row = ...)
After this step, your image should look like this:

Next Step: Normal Calculation
I will explain this on the whiteboard
TODO: Implement the correct normal calculations for the sphere in Sphere::normal() in the file sphere.cpp. Because this function is not used yet, the resulting image will not change.
Next Step: Ambient and Diffuse Lighting
I will explain this on the whiteboard
- If you were not at this class, read Section 6.3 in your book to find out how to implement this and/or look at the links at the bottom of this page.
TODO: Implement the diffuse term of Phong's lighting model to obtain simple shading. Modify the function Raytracer::trace(Ray) in the file raytracer.cpp. This step requires a working normal calculation.
After this step your image should look similar to this:

TODO: Now add the ambient term in the lighting calculation.
Now the image should look similar to this:
