Up to now, all our onscreen objects have been defined by constant material colors. In order to improve perception, we need to add lighting and shading effects. We must consider two things: the lights and the surface materials.

Objects we see must be lit by a light source. So, we are concerned with the light arriving at the object's surface and then the light that is reflected into our eyes. We will consider lighting according to a commonly used rendering equation:

$$ L_o = Le + \int{\Omega} F_rL_iD $$

Where \(L_o\) is the light output from the surface, \(L_e\) is the light emitted from the surface (i.e. a glow), \(F_r\) is the material reflectance factor, \(Li\) is the amount of light arriving at the surface, and \(D\) is the angle of the arriving light. The input values are integrated over a hemisphere (the \( \int{\Omega} \) term).

We first consider the light arriving at the surface: \(F_rL_iD\). We will use very simple light models in this class for performance and usability reasons: ambient light, point lights, spotlights, and directional lights. For all of these lights, we want to determine what incoming intensity \(I\) they cause at a surface.

Point lights

Point light sources are infinitesimally small light sources that emit some light energy. This is not physically accurate, but is very convenient for modeling computer graphics. The point light has position and intensity values. The intensity values are often stored as an RGB triple.

A light's intensity can be defined as an RGB triple. Here's an example of a light's intensity value:

$$ I = \left[I\mathrm{r}, I\mathrm{g}, I_\mathrm{b}\right] $$

Spot lights

Spot lights are similar to point lights, except their output is restricted to a certain direction. The spotlight has position, intensity, direction, and a falloff factor. If the light is pointing in direction \(l_s\) with intensity \(I\), then the intensity falls off with \(I \cos{\phi}\^e \), where the \(e\) term controls the falloff rate.

Directional lights

These are very distant point light sources, like the sun. They work like point lights, but their position \(p\) is infinity far away:

$$ p = \left[x, y, z, 0\right] $$

This results in a light source at infinity, causing all light rays to be parallel. This type of light should not be affected by attenuation.

Area lights

Real lights are not points and always have a light emitting surface area. Mathematically modeling lights with area is challenging. To compute the light arriving at a surface point from an area light, we would need to evaluate how much of the area light is visible to the surface point. This can be solved analytically in simple cases. In most situations, there is no analytical solution and the area light must be repeatedly sampled to find the light contribution at the surface point. This is often computationally expensive.

The sampling process for area light sources is similar to using many point sources. The area light is approximated with a large number of point sources. Each point source represents a sample of the light reaching the surface point. If enough points are used, the result is similar to area light methods and also has similar computational cost.

Ambient light

In the physical world, photons emitted by a light source bounce off surfaces thousands of times before they are absorbed beyond human perception. This results in lighting surfaces that are not directly in line-of-sight of a light source. An example of this is the roadway beneath a car. There is no direct path for light to reach under the car, yet the road can still be seen. These effects are called Global Illumination because the lighting at any surface is dependent upon the reflectance of all global objects.

Modeling global effects is very challenging. Instead of correctly modeling global lighting, we will use an ambient light value: a low intensity light value is said to be arriving at all surfaces in the scene. This is a cheap, mostly reasonable way to approximate the effects of global lighting.

The ambient light factor can be set globally, or can be modeled per light. If modeled per light, the final ambient value is the sum of each light's ambient factor.

Light Attenuation

Attenuation is the loss of intensity over distance. The farther the distance, the more the light energy spreads out over space and less arrives per unit area at the surface. Point lights and spotlights look much better if attenuation is considered. The attenuation factor is based on the distance between the light source and the surface. Physically, the intensity falls off according to the inverse square law. For a light at position \(p_1\) with intensity \(I_p\) and a surface point \(p_0\), the arriving intensity \(I\) is:

$$ I = \frac{1}{|p_1-p0|\^2}I\mathrm{0} $$

Physically based attenuation often appears too strong in virtual environments. For distance \(d\), a flexible attenuation equation is often used:

$$ (a + bd + cd\^2)\^{-1} $$

The coefficients allow easy scaling of the constant, linear, and quadratic falloff terms. The attenuation factor can then be applied to the intensity:

$$ I = aI_\mathrm{p} $$


Once a light is defined, it can interact with objects in the scene. The object's materials will change how the light energy is perceived by the viewer. We will primarily be concerned with how light reflects off matte surfaces and shiny surfaces.