Adding material and lighting
The most important properties for a mesh, other than the vertices themselves, are material and lighting. With the ability to specify the texture, color, and the way the surface behaves with lighting, we can generate much more realistic scenes.
In the previous recipe, we have already added two of the three input vectors needed for calculating the lighting:
View direction (calculated from the camera's location)
Surface normal
The final input vector is light direction. For this sample, we are going to create a simple directional light, that is, a light that has a constant direction anywhere in the scene (like the sun). We will define this light with a color and direction.
We also introduce the following material properties:
Ambient light color: The ambient reflection is a constant ambient-lighting value. This is a simple, approximate representation of light that has bounced around a room and is lighting the back of the object, providing the indirect light. This value...