Specular reflection and Phong shading/lighting

Specular reflection has been implemented according to plan, recursively calling the raycasting function with new rays that have been given new directions according to the law of reflection.

A highly reflective sphere on the floor of the Cornell box

Phong shading and lighting has been added as well, presenting somewhat more of a challenge. Barycentric coordinates are computed and used to interpolate normals across triangles. Switching to actually reading and using individual vertex normals (instead of the edges-cross-product surface normal of each triangle) caused the backface culling code to stop working as it relied on the first vertex of each triangle having a normal vector value set to the surface normal vector. This was corrected by adding a new property to our Triangle structure to hold the geometric surface normal which is then used for backface culling.

The wireframe mode has been enhanced with the ability to draw both vertex and surface normals. In the following picture vertex normals are drawn in yellow and surface normals are drawn in red.

Normals shown in wireframe mode

Some pictures of the stages of Phong implementation:

Before implementing Phong shading and lighting

Phong shading (interpolation of vertex normals)

Phong shading combined with the Phong lighting model. The specular highlights are now controlled by a shininess parameter and are dependent on view angle

Putting it all together. Two lights in this scene!




Comments