29. Mathematics of Lighting and Shading part 3
Dated: 01-07-2025
Traditional 3D Hardware-accelerated Lighting Models
The traditional approach in real time computer graphics has been to calculate lighting
at a vertex
as a sum of the ambient
,1 diffuse
,1 and specular light
.1
This is called a local lighting model
since the only light
on a vertex
is from a light source
, not from other objects. The reflection coefficients
\(k\) are in the \([0, 1]\) range and are specified as part of the material property
.
However, it does fail to take into account any gross roughness
or anything other than perfect isotropic reflection
.
Ambient
1 Light
It is a light
which comes from all directions (i.e. the environment) but there are too many sources and it would talk a lot of resources to compute so we just have an \(x\) value for simplicity and we call it ambient light
1 which equally illuminates all objects.
Where \(i_a\) is ambient light intensity
, \(m_a\) is ambient material color
and \(s_a\) is light source ambient color
.
Diffuse light
Diffuse light
1 is the light that is absorbed by a surface and is reflected in all directions. Regardless of the direction from which we view an object with a stationary diffuse light
1 source on it, the brightness of any point on the surface will remain the same. Thus, unlike ambient light
,1 the intensity
of diffuse light
1 is directional and is a function
2 of the angle of the incoming light
and the surface. This type of shading is called Lambertian shading
after Lambert's cosine law
, which states that the intensity
of the light
reflected from an ideal diffuse
1 surface is proportional to the cosine
of the direction of the light
to the vertex normal
.3
There are per-vertex
normals
3 in with each vertex
has a normal
3 associated with it and then there are per-polygon
normals
3 which have one normal
3 shared across all vertices
of the polygone
.
OpenGL
can specify per-polygon
normals
3 but Direct3D
cannot.
here \(\hat l\) is the direction to the light source
.
Practically speaking, we don't want vertices
where light
cannot shine on
Dotted line illustrates direction of light
from source to surface. The dot product
4 for light
inside the surface will be negative
.
Problem with diffuse light
1 alone is that, it is independent of the viewing angle.
Specular light
While ambient light
1 gives the object an illuminated matte surface
, specular light
is what gives the highlights
to an object. These highlights
are greatest when the viewer is looking directly along the reflection
angle from the surface
.
Phong's Specular light Equation
Warnock [WARNOCK 1969]
and Romney [ROMNEY 1969]
were the first to try to simulate highlights
using a \(\cos (n \theta)\) term. Phong Bui-Tong [BUI 1998]
reformulated this into a more general model that formalized the power value as a measure of surface roughness
that we approach the terms used today for specular highlights
.
\(i_s = (m_s \otimes s_s) (\hat r \cdot \hat v)^{m_s}\)
The \(m_s\) factor
The larger \(m_s\) value is, the tighter the specular highlights
are.
The \((\hat r \cdot \hat v)^{m_s}\) for \(m \in [0, 1]\) doesn't get any brighter.
Proof
- \(\vec r \cdot \vec n = \vec l \cdot \vec n\)
- \(2(\vec r \cdot \vec n) = 2(\vec l \cdot \vec n)\)
- \(2(\vec r \cdot \vec n) \cdot \vec n = 2(\vec l \cdot \vec n) \cdot \vec n\)
- \((\vec r \cdot \vec n) \cdot \vec n + (\vec r \cdot \vec n) \cdot \vec n = 2(\vec l \cdot \vec n) \cdot \vec n\)
- \(\vec r \cdot \vec n \cdot \vec n + \vec l \cdot \vec n \cdot \vec n = 2(\vec l \cdot \vec n) \cdot \vec n \quad \because (\vec r \cdot \vec n) = (\vec l \cdot \vec n)\)
- \(\vec r |n|^2 + \vec l |n|^2 = 2(\vec l \cdot \vec n) \cdot \vec n\)
- \(|n|^2(\vec r + \vec l) = 2(\vec l \cdot \vec n) \cdot \vec n\)
- \((\vec r + \vec l) = \frac{2(\vec l \cdot \vec n) \cdot \vec n}{|n|^2}\)
- \(\vec r = \frac{2(\vec l \cdot \vec n) \cdot \vec n}{|n|^2} - \vec l\)
The equation simplifies if \(\vec n\) and \(\vec l\) are normalized
Blinn's Simplification: OpenGL
and DirectX
Lighting
where \(\vec h\) is the half angle vector
4 and is defined as