Just because an object has a colour doesn’t mean it gives off that colour. This is because the color the camera sees is dependent on the amount of light falling on it and how reflective an object.

Diffuse Reflection

Diffuse Reflection is light which is reflectively distributed uniformly - Large amounts indicate a matte surface.


Specular Reflection

Specular Reflection is light bouncing off in one direction. Shiny surfaces have specular reflection


Ambient Lighting

Ambient lighting is to account for the fact that computing the reflection of light from all sources each frame is expensive - instead we set a minimum amount of light for every object to have.

Computing Illumination


The amount of light the camera receives from a point P


The necessary variables to calculate Illumination

Computing Diffuse illumination

The amount of reflected light is inversely proportional to the area of the face subtended by the source. Malcolm formalised this from Tim Lambert using the little known Lambert’s Law:


(when cos is negative we are behind the object and so we simply take the max of 0 and the other term)


Light surfaces have coefficients close to 1, dark values close to 0. GL MATERIAL can set the reflection coefficient.

Computing Specular illumination (PHONG)

Because only mirror’s reflect perfectly (no scattering) we use approximations to do specular lighting. Phong Shading is a good model of this (better for surfaces where we add light highlights rather than reflections - e.g. plastic, not polished metal).

The Phong equation for calculating specular illumination is below.



Large f values produce less scattering (e.g. more mirror like surfaces)


Reflection is brightest around the reflection vector, and intensity drops off with 𝜑 (hence its use in cos above)

Phong only reflects light sources, not environmental light (e.g. light bouncing off other things).

Ambient Lighting

Ambient Lighting is a constant added on so we can forget about light coming from non light sources.

Combined - All Together Now

The original algorithm ignored the fact that there are multiple lights however it is a simple change to sum the specular and diffuse results for each light.



Colour is implemented by having separate rgb components for
the light intensities of Ambient light and Individual diffuse+specular light values
reflection coefficients (of ambient, diffuse and specular)

The lighting equation is performed for each component. To get the colour of a vertex you multiply its colour by its colour light value.


Points/Directions (Directional Lighting)

Lights can come from points in the world (meaning the Light vector is different depending on the point p) Or these lights can be directional meaning that the light vector is the same for all points.

To specify a directional light simply use a vector rather than a point.


Imagine trapping a light source in a box and only opening one side. This is a spot light. Spotlights need a direction and a cut off angle.



There are two attenuations when talking about lights. One is how quickly it drops off compared to the angle straight out of the light source.



Use this formula to compute this falling off. (E is the attenuation factor)


The other Attenuation is the attenuation due to distance from the light source. Use this formula to compute this attenuation. The default is attenuation of 1 (which is to say, no change due to distance)

Global Illumination

In reality, light is bounced and reflected off every surface on to every other surface - light comes from everywhere.

Multi-bounce lighting methods are called global lighting methods. Ray tracing and radiosity are the 2 main ones, and they’re both so computationally expensive they can’t really be used in real time.