3D Lighting 102

Background

Local Models versus Global Models

Light is emitted from sources in an environment, and that light bounces all around the environment, generally illuminating all surfaces to some extent. In addition, some objects in an environment have surface and/or material properties that allow us to see reflections of other objects and/or see refracted images of objects behind them.

The effects mentioned above – multiple light reflections, reflected images of objects on the surfaces of others, and the ability to see through translucent objects – are generally called global lighting effects. In pipelined graphics engine architectures such as that present in OpenGL, such global effects are at best difficult to model in a general way. Various global approaches (e.g., ray tracing and radiosity) are typically used to simulate these effects. We will restrict ourselves to the study of local lighting models which explicitly do not attempt to simulate shadows (which are a side effect of how light scatters in an environment), reflections, and refraction.

Empirical Models versus Physically-Based Models

Local models simulate the physics of light-surface interaction. A large number of local lighting models have been developed over the years, all based on geometric considerations along with various loose approximations to the underlying physics. The classical model used in pipelined graphics architectures (and in many ray tracers) is based on the Phong local lighting model. Other models that attempt to simulate more precisely the actual physics have been developed. While capable of producing extremely realistic results (see the figure on the right), they are considerably more computationally intensive and require a not insignificant amount of "tuning". Increasing GPU performance in recent years coupled with the fact that the shader stages are fully programmable makes it more reasonable to implement such advanced reflection models. Nevertheless, we will study only the classical Phong model since it is sufficiently complex for our purposes, easier to utilize, and produces perfectly good results for our purposes.

Electromagnetic Radiation and Color

We can understand one aspect of the difference between empirical and physically-based models by reviewing something of the physics of electromagnetic radiation and color. Physical models attempt to sample a large number of reflected wavelengths; empirical models such as the Phong model we are about to study sample at just three wavelengths, corresponding roughly to blue, green, and red, respectively.

Extensions From Lighting Model 101

  1. There will be an arbitrary number of light sources. (However because of constraints in GLSL and our use of uniform arrays, we will need to enforce at compile time a maximum number of sources.)
    In 101: 1 source
  2. For each light source, we will store and send to the fragment shader via uniform variables:
  3. For each light source, we will store, but not send to the fragment shader: The lighting model in the fragment shader will assume the lights are defined in EC just like in the 101 model. The difference is that we will apply the current mc_ec matrix to any light source geometry defined in MC before sending it to the uniform in the fragment shader.
  4. The effective light source strength at a given point in a scene of a positional light source (i.e., one that is placed in the scene at some (x, y, z, w) where w=1) falls off with the square of the distance from the source to the point. We will take this attenuation into account.
    In 101: attenuation was ignored

Hints for Modeling Your Lighting Environment

Creating a good lighting environment is required in order to get satisfying rendered results. It is also harder than you might think.

Reflection Geometry

The basic geometry of reflection assumed by the Phong Empirical Local Lighting Model

Determining the and Unit Vectors

Get EC Representations of the Light Source Positions/Directions

If the ith light source is defined in MC, the first step is to transform it to EC using the current mc_ec matrix. This can be done on the CPU before sending the data down, or on the GPU in the fragment shader.

Vector towards the ith light source,

There are two common ways to determine the unit vector towards the light source:

"Perfect" reflection vector for the ith light source,

Decompose into its components parallel to and perpendicular to . Then is (the parallel component - the perpendicular component):

2*(·) -

The Phong Model Equations

Classical Phong Local Lighting Model

Reflectance Data For Phong Models

Some Phong model values for common materials