3.1. Lighting

3.1.1. Phong Lighting Model

Lighting is based on the Phong model, which states that for every object, we can see light reflected from it in three ways:

  • Ambient light;
  • Diffuse reflection; and
  • Specular reflection.
../../_images/light-reflections.gif

3.1.1.1. Ambient light

Usually light gets reflected from surfaces and walls, so entire scenes have a small amount of light even when they are not pointing towards the light source.

We can model that (unrealistically) using ambient light: giving the entire scene a small amount of light that is applied to all objects.

This is not realistic, but does a reasonably good job and does not entail a performance loss.

3.1.1.2. Diffuse reflection

This is light that gets reflected in all directions when a light ray hits a surface.

When the surface is parallel to the ray of light, it does not get hit, and so no diffusion can take place.

When the surface is perpendicular to the ray, maximum diffusion takes place. This follows Lambert’s Law [1]:

R_d = I_dK_dcos(\theta) = I_dK_d(N.L)

Where:

  • \(I_d\) is the intensity of the incoming light ray.
  • \(\theta\) is the angle between the light and the surface normal.
  • \(K_d\) is the diffusion constant, the “non-glossyness” of the surface.
  • \(N\) is the surface normal vector.
  • \(L\) is the direction of the light coming from the light source.

3.1.1.3. Specular reflection

A Specular Highlight is the reflection we see when the angle of incidence equals the angle of reflection, and our eye is in position at that angle to see the reflection.

For a perfectly glossy surface, the specular highlight can only be seen for a small \(\theta\), as in below:

../../_images/specular.png

However, for a non-glossy surface, there is a range of \(\phi\) where the specular highlight can be seen.

The equation is as follows:

R_s = I_sK_scos^{n}(\theta)

Phong suggested a large value of \(n\) for a large range of \(\phi\), and a small value of \(n\) for a small range.

3.1.1.3.1. Blinn-Phong approximation

The Blinn-Phong approximation is used in OpenGL as a means to simulate the equation but made simpler.

../../_images/specular-approximation.png

Instead of using the angle between \(R\) and \(V\), we calculate \(S\) which is between \(L\) and \(V\). Then, we use the angle between \(S\) and \(N\).

3.1.1.4. Emitted light

An object can emmit light, and this simply means that we program it to be bright, as if it were a source of light.

Remember that making an object bright does not mean it will be making other objects bright. A source of light and an object that looks lit can be different things in OpenGL.

3.1.1.5. Attenuation

The intensity of the light must decrease the further away from the light we are, unless the light is directional, and not positional.

Although light intensity can be calculated with a number of formulas (e.g. the square of the distance from the light), we can use a more complex formula when programming graphics:

1\over{k_c+k_{l}d+k_{q}d^2}

Where \(k_c\), \(k_l\), and \(k_q\) are constants, and \(d\) is the distance from the light for any given position.

Footnotes

[1]Lambert’s Law states that the intensity of the diffused light is proportional to the cosine of the angle between two vectors, the surface normal and the direction of the light source.