Title: Illumination and Shading
1School of Computing Staffordshire University
3D Computer Graphics
Illumination and Shading
Dr. Claude C. Chibelushi
2Outline
- Introduction
- Light
- Sources, Propagation
- Illumination Models
- Ambient illumination, Diffuse reflection,
Specular reflection - Display of Polygonal Objects
- Polygon Shading
- Constant, Gouraud, and Phong shading
- Summary
3Introduction
- Photorealism accurate representation of
- shape of object(s) collection of flat / curved
surfaces - vertex coordinates, surface equations
- occlusion
- optical properties of object(s) and light
source(s) - brightness (shiny / dull), colour, texture,
transparency (opaque / transparent), shadows, ...
4Introduction
- Accurate representation of shape, occlusion, and
optical characteristics - costly, hence approximations often used, e.g.
- set of polygons for shape approximation
- surface shading based on empirical procedures
(i.e. not strict physical laws) - Shading of surfaces
- calculation of intensity of points on surface
- intensity typically calculated using illumination
(or lighting) model
5Light
- Propagation
- Light incident onto surface can be
- reflected (bounces off as reflected light
ray(s)) - transmitted (as observed in glass)
- absorbed (converted to heat or other energy form)
- Visual characteristics of object relate to amount
and nature of light from object to eye
6Light
- Propagation
- Amount and direction of light reflected,
transmitted, or absorbed - depends on material of object, and light
wavelength (colour) / intensity / position - Viewer sees light reflected along rays from
points on object surface to eye position
7Light
- Propagation
- Light reaching point often combination of light
from - light-emitting sources (commonly called light
sources) and light-reflecting sources - Object properties affect light reflected by
object, hence surface labels describing - amount of reflected light
- shiny / dull, opaque / transparent
- direction of reflected light
- grainy or rough / smooth
8Light
Simple light emitters
9Light
Diffuse reflection (scatter)
Specular reflection (highlight)
Simple light reflectors
10Illumination Models
(Parameters position, directionality, colour,
intensity)
(Parameters position, orientation, optical
properties)
(Parameters position, orientation)
(Parameters position, orientation, optical
properties)
Effect of illumination interplay of many factors
11Illumination Models
Note Colour representation requires computation
of intensity in each colour band (e.g. R, G, B)
Parameters
12Illumination Models
- Illumination model
- formula for calculating light intensity seen at
surface point - computation based on
- optical properties of surface
- relative positions of surfaces in scene (shadows,
) - position, shape, colour and intensity of light
source(s) - position and orientation of viewer
13Basic Illumination Models
- Basic illumination models
- simplified (empirical) methods for calculating
intensity at given surface point - calculations based on optical properties of
surface, lighting and view specifications - light sources point sources with specified
position and colour
14Basic Illumination Models
- Ambient illumination
- Ambient light or background light
- defines general brightness of scene
- models combination of emissions / reflections
from various sources in scene - global diffuse lighting effect
- constant throughout scene
- independent of position and direction of object /
viewer
15Basic Illumination Models
- Ambient illumination
- Same incident light Ia throughout scene
- but intensity of reflected light depends on
optical properties of surface - Fraction of incident light reflected by surface
- determined by ambient-reflection coefficient
(ka) - Ir, amb ka Ia 0 ? ka ? 1 (depends on
surface properties)
16Basic Illumination Models
- Diffuse reflection
- Independent of viewing direction
- Virtually constant over each surface (for distant
light source) - Fraction of incident light reflected by surface
is determined by - orientation of surface relative to light source
- diffuse-reflection coefficient (kd)
- 0 ? kd ? 1 (depends on surface properties)
17Basic Illumination Models
- Diffuse reflection model implementation
Reflected light is Ir, diff kd Ii cos ? If n
and t are unit vectors Ir, diff kd Ii (n ? t )
18Basic Illumination Models
- Specular reflection
- Models highlights or bright spots on illuminated
shiny surfaces - Theoretical specular reflection
- single reflected ray
- specular reflection angle is equal to angle of
incidence - In reality multiple reflected rays (cone)
19Basic Illumination Models
- Specular reflection
- Phong specular-reflection model
- Fraction of incident light reflected by surface
and seen by viewer is determined by - orientation of surface relative to light source
and viewer - specular-reflection coefficient (ks) 0 ? ks ? 1
(depends on surface properties) - specular-reflection parameter (ns) high value
(say ns gt 100) for very shiny surface - depends on surface properties (ns is also known
shininess parameter)
20Basic Illumination Models
- Specular reflection model implementation
Viewed reflected light is Ir, spec ks Ii cosns
?
21Basic Illumination Models
- Specular reflection model implementation
- If n, t, and v are unit vectors
- Ir, spec ks Ii (v r) ns
- where r (2n t) n t
- Possible geometric simplification
- assume point light source at infinity
- hence t considered constant for scene
22Basic Illumination Models
- Specular reflection effect of ks and ns
23Basic Illumination Models
- Combination of reflections
- For single point source
- sum up ambient, specular, and diffuse intensities
- Ir, tot Ir, amb Ir, diff Ir, spec
- where ka kd ks 1
- For multiple point sources
- sum up total intensities (computed as above) for
all sources
24Basic Illumination Models
- Colour scenes
- Alternative 1 for each colour component (e.g.
red, green, blue RGB) - specify properties of light-source and surface
material - specular highlight looks like reflection of light
source - hence set proportions of ks across colour
components to match colour of light source - apply illumination model(s)
25Basic Illumination Models
- Colour scenes
- Alternative 2
- surface colour modulates reflection coefficients
- e.g. for white light source
- same light-source parameters for RGB components
- same material coefficients / parameters for RGB
components - but possibly different RGB components for surface
colour
surface colour
ambient reflection
diffuse reflection
specular reflection
26Basic Illumination Models
- Directional light source
- If t and s are unit vectors
- Ispot Ii cosm ? Ii (-t s) m
- use Ispot in place of Ii in reflection formula
27Basic Illumination Models
- Attenuation of light due to travel distance
- may be modelled by inverse linear or quadratic
function - Note reflected light calculated in world or
viewing coordinates - i.e. before perspective transformation is applied
- perspective and shear transformation may change
orientation of surface normals!
28Display of Polygonal Objects
- Wireframe
- faces represented by line segments connecting
vertices - may use colour or broken lines for depth cueing
- Filled solid
- faces filled with single colour
- no illumination model used
- adjacent faces appear as one surface
29Display of Polygonal Objects
- Shaded solid
- faces shaded with intensity calculated from
suitable illumination model(s) - illumination model(s) typically applied to
- single point (calculated intensity used for
shading whole polygon) constant shading - some points (calculated intensities interpolated
to obtain intensity at other points) e.g.
Gouraud shading - all polygon pixels e.g. Phong shading
30Polygon Shading
- Constant / Flat shading
- Face filled with single shade calculated from
suitable illumination model(s) - Low realism but better than filled models
- may require smoothing (close to face junctions)
- Pseudocode
- for each face
- apply illumination model to a point on the
face - fill face with calculated intensity
-
31Polygon Shading
- Gouraud shading
- Intensity-interpolation shading
- calculate intensity at polygon vertices
- interpolate intensity values across surface
- interpolation weighted averaging
- Less intensity discontinuity along edges than in
flat shading
32Polygon Shading
- Gouraud shading (ctd.)
- Calculation of intensity at polygon vertices
- compute normal vector at each vertex
- e.g. sum up surface normals of polygons sharing
vertex - convert to unit vector
- compute intensity at each vertex
- apply illumination model(s) to vertex
33Polygon Shading
- Gouraud shading (ctd.)
- Interpolation of intensities along polygon edges
- compute intensity at intersection of scan-line
with edge - interpolate intensities at edge endpoints (2
vertices) - compute intensity at interior points
- interpolate intensities at edge points (along
scan-line)
34Polygon Shading
- Gouraud shading (ctd.)
- Interpolation of intensities
Shading is often coupled to scan conversion
35Polygon Shading
- Gouraud shading (ctd.)
- Exploiting coherence
- use incremental computation
- add a constant step to I value of previous point
to obtain I value of current point (for
increasing y or x) - it can be shown that
- along polygon edge
- Icurrent Iprevious (I1 - I2) / (y1 - y2)
(along edge between 1 and 2) - Icurrent Iprevious (I1 - I3) / (y1 - y3)
(along edge between 1 and 3) - along scan line
- Icurrent Iprevious (I5 - I4) / (x5 - x4)
(along scan line between 4 and 5)
36Polygon Shading
- Gouraud shading pseudocode
- for each face
- compute unit normal at each vertex
- apply illumination model(s) to each face
vertex - for each scan line
- compute intensity at face edges from relevant
- vertex intensities
- for each interior scan-line pixel compute
intensity from relevant - edge intensities
-
-
37Polygon Shading
- Phong shading
- Normal-vector interpolation shading
- calculate unit normal vector at each vertex
- interpolate vertex normals across surface
- apply illumination model(s) along each scan line
- Better realism than Gouraud shading
- but higher computational cost
- vector interpolation illumination model(s)
applied to each pixel
38Polygon Shading
- Phong shading (ctd.)
- Calculation of unit normals at polygon vertices
- as in Gouraud shading
- Interpolation of surface normals along polygon
edges - compute normal at intersection of scan-line with
edge - interpolate normals at edge endpoints (2
vertices) - compute normal at interior points
- interpolate normals at edge points (along
scan-line)
39Polygon Shading
- Phong shading (ctd.)
- Interpolation of surface normals
Efficiency incremental calculations can be used
40Polygon Shading
- Phong shading pseudocode
- for each face
- compute unit normal at each vertex
- for each scan line
- compute normal at face edges from relevant
- vertex normals
- for each interior scan-line pixel
- compute normal from relevant edge normals
- apply illumination model(s) to pixel
-
-
-
41Polygon Shading
- Comparison of techniques
- Constant shading
- Face filled with single shade
- Low realism
- Low computational and storage cost
42Polygon Shading
- Comparison of techniques
- Gouraud shading
- Vertex intensity interpolation
- Prone to Mach band effect
- May fail to show highlights
- hence surfaces may appear dull / matt
- Slower but better realism than flat shading
43Polygon Shading
- Comparison of techniques
- Phong shading
- Vertex normal interpolation
- illumination model(s) applied to each pixel
- deals well with highlights
- more rounding of polygon seams than Gouraud
shading - Higher computational cost but better realism than
Gouraud shading
44Suggested Reading
- Relevant parts of Ch. 9 Ch. 14, D. Hearn, M.P.
Baker, Computer Graphics, 2nd Ed. in C,
Prentice-Hall, 1996. - Relevant parts of Ch. 10 Ch. 12, A. LaMothe,
Black Art of 3D Game Programming, Waite Group
Press, 1995.
45Summary
- Illumination model gives intensity of surface
points - calculated intensity is used for shading surface
- Basic illumination models
- ambient illumination, diffuse reflection,
specular reflection - combination of intensities sum of contribution
of models and light sources - model(s) applied to / modulated by each colour
component
46Summary
- Polygon shading illumination model(s) applied
for - single pixel (constant / flat shading), vertex
pixels (Gouraud shading), all surface pixels
(Phong shading) - increasing realism and computational cost