Illumination and shading

From DmWiki

(Redirected from Lighting)

Lighting is often referred to as illumination and shading models. The term "illumination" refers to a model for where light comes from in the scene, while "shading" refers to how the color of a surface is calculated, given a method for finding the illumination on it.

There is a standard illumination model applied in 3D graphics, in which light consists of two components:

  • Ambient light is a very small amount of light that falls on every surface equally and pervades the entire scene. This prevents the areas where there is no direct light from being completely black - you will still be able to see a little. Ambient light does not "really" exist, but is an approximation for indirect lighting (when light from a light source bounces off surfaces and illuminates areas that the light source can't reach directly).
  • Direct light is light that comes straight from a light source. Light sources are usually modelled as points in space, because although real lights are not points, "area lights" are too computationally intensive to simulate in a real-time 3D application.

Also note that there are various terms and definitions used frequently in lighting:

Some examples of illumination and shading models are:

The Lighting Equation

The most common kind of equation used to find the color of a lit object contains terms for ambient and direct light, with the direct light being broken up into diffuse (view-independent) and specular (view-dependent) components:

c_{final} = c_{diff}k_{amb} + \sum_{i = 1}^{n} c_{light_i} \left( c_{diff} k_{diff_i} + c_{spec} k_{spec_i} \right)

Here, the variables are as follows:

  • cfinal is the final color that you see on the screen
  • n is the number of light sources
  • c_{light_i} is the color of the ith light source
  • cdiff is the diffuse color of the surface, which is normally given by a texture
  • cspec is the specular color of the surface, which is normally white or gray, and can be constant or a texture
  • kamb is the ambient light coefficient, usually a small number like 0.1 that is constant over the whole scene
  • k_{diff_i} is the diffuse coefficient for the ith light, as calculated by the illumination model
  • k_{spec_i} is the specular coefficient for the ith light, as calculated by the illumination model

Basically, the global ambient light is multiplied by the object color, and then for each light its diffuse and specular terms are calculated and then added up. See Phong shading for a popular method of computing the diffuse and specular coefficients.


DevMaster navigation