26. Mathematics of Lighting and Shading part 2
Dated: 01-07-2025
Light Types
Parallel or Directional Lights
These are used to simulate sun
(93 million miles) and makes math easy. The attenuation
factor is always \(1\) (for point
or spotlights
, it generally involves divisions
if not square roots
). Because they are simpler, the frame rates remain reasonably high enough.
Point Lights
These are one step better than parallel lights and we have intensity falloff
as
Point Light
Spotlights
These should be avoided and are not for real time environment.
The inside cone defined by \(\theta\) angle and outside cone defined by \(\phi\) .
The light from inner cone to the outer cone has a linear fade out effect (i.e. the intensity depends upon how close a point is to the inner cone).
Linear fade out effect
Shading Models
Lambert
Triangles
that use Lambertian shading
are painted with one solid color instead of using a gradient. To light a triangle
, you compute the lighting equations using the triangle
's normal and any of the three vertices of the triangle
.
Flat Shaded
Gouraud
Gouraud
(pronounced garrow) shading is the current de facto shading standard in accelerated 3D hardware. Instead of specifying one color
to use for the entire triangle, each vertex
has its own separate color
. The color
values are linearly interpolated across the triangle, creating a smooth transition between the vertex
color
values. To calculate the lighting for a vertex
, we use the position of the vertex
and a vertex
normal
.1
Flat Shading vs Gouraud
One problem with Gouraud shading
is that the triangles
' intensities
can never be greater than the intensities
at the edges. So if there is a spotlight shining directly into the center of a large triangle
, Gouraud shading
will interpolate the intensities
at the three dark corners, resulting in an incorrectly dark triangle
.
Phong
Phong
is relatively more realistic as it makes highlights
on the surface (i.e. shininess). The way Phong
does this is by interpolating the normal
1 across the triangle
face, not the color
value, and the lighting equation is solved individually for each pixel
.2
Phong
Source: metaltutorial.com
References
-
Read more about surface normals. ↩↩