Now we finally get to make the objects in our scene reflect local illumination. Do read the Shading and Lighting topic's materials if you have not done so already.
In this task we will be implementing two sets of shaders for our objects. One set (vertex + fragment) will be for the Gouraud shading (per-vertex lighting) and the second will be for the Phong shading (per-fragment lighting). For both cases implement the Phong's lighting model (ambient term + diffuse/Lambertian term + Phong's specular term).
You will need the following normalized vectors in your shaders:
The vector $r$ can alternatively be the reflection of the viewer incident vector. The angle between the reflected viewer incident and $l$ and the reflected light incident and $v$ will be of the same size. Because cosine is symmetric, the specular term in the lighting model will be of the same value.
or |
For the diffuse term you need to use the cosine of the angle between $l$ and $n$.
So overall you need to use the dot product $l \cdot n$ for the diffuse term and $v \cdot r$ for the specular.
In order to see more clearly the difference between the Gouraud and Phong shading, let us make the body of the chopper to be a very crudely approximated sphere.
Task is to implement the aforementioned shaders to get a result similar to the images below. When implementing the shaders, remember that the calculations will be done in the camera space. This means that the viewer position is actually the origin.
For Gouraud:
For Phong:
Describe in the task submission why is Gouraud missing a specular highlight on the back wall?