Skip to content

25. Mathematics of Lighting and Shading part - 1

Dated: 01-07-2025

Lights and Materials

Light can have following properties

  • Color (rgb)
  • Intensity
  • Attenuation (a function1 of light intensity where intensity decreases as distance from light source increases)
  • Shapes
  • Positions

Light interact with the material surface in following ways

  • Surface bounce
  • Absorption
  • Transmission
  • Scattering

Materials are described using the following colors

  • Ambient
  • Diffuse
  • Specular
  • Emissive

Emissive lights are for objects which generate their own light and ambient is usually grouped with specular.

Ambient Lighting

It's a global value that is added to each object in the scene and is used general environmental illumination. It is the general color of objects due to the global ambient light level.

Diffuse Lighting

It is the color of the object due to specific light effect on an object (matte). The light is reflected in all directions and depends only on the able between the incident light array and surface normal.2

Specular Lighting

It is the color of the highlights on the surface. The specular light mimics the shininess of a surface, and its intensity is a function1 of the light's reflection angle off the surface.

Emissive Lighting

These are lights emitted by the objects themselves. Shading is simply calculating the color reflected off a surface (which is pretty much what shaders do). When a light reflects off a surface, the light colors are modulated by the surface color (typically, the diffuse or ambient surface color).
Let \(l = (r_l, g_l, b_l)\) be the color of light and \(s = (r_s, g_s, b_s)\) be color of the surface then the resulting color is

\[c = l \otimes s\]
\[c = (r_l \times r_s, g_l \times g_s, b_l \times b_s)\]

So a shader might typically do the following:

  • Calculate the overall ambient light on a surface.
  • For each light in a scene, calculate the diffuse and specular contribution for each light.
  • Calculate any emissive light for a surface.
  • Add all these lights together to calculate the final color value.

For materials like metal(conductive), most of the light is reflected and for dielectrics (non conductive), most of it is penetrates.
The dispersion of light is a function1 of the roughness of the surface.

cs602_i_25_1.png

Light dispersion

cs602_i_25_2.png

Sub surface scattering

cs602_i_25_3.png

3 Shader passes into final lighting

References


  1. Read more about functions

  2. Read more about surface normals