Rendering a geometry with a vertex diffuse lighting
A basic diffuse lighting algorithm lies at the core of most lighting calculations. It is used to simulate the appearance of matte surfaces that reflect the light, scattering it in many different directions. In this recipe, we will see how to achieve geometry rendering using vertex and fragment shaders that implement the diffuse lighting algorithm.
An example of an image generated with this recipe looks like the following:

Note
The following recipe is very detailed so that you can understand and follow all the steps more easily. Further recipes will be based on the knowledge described here, so they are shorter but also more general.
Getting ready
Diffuse lighting is based on a cosine law introduced by Johann Heinrich Lambert. It says that the lighting intensity of an observed surface is proportional to the cosine of the angle between the direction from the surface to the source of light (a light vector) and the surface normal vector:

This law...