Title: Computer Graphics
1Computer Graphics
- Lecture 7
- Illumination and Shading Algorithms
- Lecturer Heather Sayers
- E-mail hm.sayers_at_ulster.ac.uk
- URLhttp//www.infm.ulst.ac.uk/heather
2Contents
- Introduction
- The Projective Rendering Pipeline
- Light Sources
- Shading models Flat, Gouraud, Phong
3Introduction
- Realistic displays of a scene are obtained by
generating perspective projections of objects and
by applying natural lighting effects to the
visible surfaces - An illumination model (lighting model/shading
model) is used to calculate the intensity of
light that we should see at a given point on the
surface of an object
4Introduction
- A surface-rendering algorithm uses the intensity
calculations from an illumination model to
determine the light intensity for all projected
pixel positions - This can be applied in 2 ways
- Applying the illumination model to every visible
surface point - Interpolating intensities across the surfaces
from a small set of illumination-model
calculations - Scan-line, image-space algorithms typically use
interpolation schemes - Ray tracing algorithms invoke the illumination
model at each pixel position
5Photorealism
- In Computer Graphics, this involves
- Accurate representations of objects
- Good physical descriptions of the lighting
effects - Lighting effects include
- Light reflections
- Transparency
- Surface texture
- Shadows
6Illumination Models
- Given the parameters for
- the optical properties of surfaces,
- the positions of the surfaces in a scene,
- the colour and positions of light sources,
- the position and orientation of the viewing
plane, - illumination models calculate the intensity
projected from a particular surface point in a
specified viewing direction - To minimise intensity calculations, most packages
use empirical models based on simplified
photometric calculations
7The Projective Rendering Pipeline
Starts with a mathematical description of the
object The object is transformed from modelling
coordinates into scene (world) coordinates (and
subsequently to device coordinates) Hidden
surfaces are identified and removed The surfaces
are illuminated Surfaces are transformed to view
coordinate space Surfaces which lie outside the
viewing frustrum are clipped Surfaces are
projected to the 2D screen Scan conversion
calculates the colour of the pixels which are
covered by the projected surfaces and writes them
into the frame buffer Video hardware scans the FB
and translates the pixel colours into analogue
signals for the CRT electron guns
8Light Sources
- An object that is emitting radiant energy, such
as a light bulb or the sun - The simplest model for a light emitter is a point
source radially diverging paths (good for
sources whose dimensions are small compared to
the size of objects in the scene) - A nearby source is more accurately modelled as a
distributed light source area of the source is
not small compared to the surfaces of the scene
9Surface Properties
- Recap on light striking surface a ray of light
strikes a surface how is that light energy
dissipated? - The answer depends on the surface
characteristics perfect reflectors (eg mirrors)
exhibit regular reflection other surfaces
exhibit diffuse reflection - For diffusely reflecting surfaces, light rays are
reflected not just in the perfectly reflected
direction but in all directions (rough, grainy
surfaces).
10Two Laws of Reflection
- 1. The reflected ray, incident ray and normal to
the surface at the points of incidence all lie in
the same plane - 2. The angle of incidence angle of reflection
N
R
I
i
r
11Specular Reflection
- Polished or shiny surfaces illuminated with a
bright light exhibit specular reflection. At
certain viewing angles the object (or part of the
object) appears to be white (the colour of the
incident light) and not the colour of the object.
- These highlights exist due to the fact that all
incident light has been reflected.
12Ambient Light
- A surface that is not exposed directly to a light
source will still be visible if nearby objects
are illuminated - In a basic illumination model, we can set a
general level of brightness for a scene this is
a simple way to model the combination of light
reflections from various surfaces to produce a
uniform illumination called the ambient light or
the background light - No spatial or directional characteristics
- Amount of ambient light incident on each object
is constant for all surfaces and over all
directions - Set the level for ambient light in a scene using
parameter Ia - The intensity of the reflected light for each
surface depends on the surfaces properties
13Diffuse Reflection
- Ambient-light reflection is an approximation of
global diffuse lighting effects - Diffuse reflections are constant over each
surface in a scene, independent of the viewing
direction - The fractional amount of the incident light that
is diffusely reflected can be set for each
surface with parameter kd the diffuse
reflection coefficient, or diffuse reflectivity - kd is assigned a constant value between 0 and 1
(highly reflective 1)
14Diffuse Reflection
- If a surface is exposed only to ambient light, we
can express the intensity of the diffuse
reflection at any point on the surface as - Iambdiff kdIa
- Scenes are rarely rendered with ambient light
alone (flat, uninteresting shading) - Usually at least one light (a point source at the
viewing position) is included - We assume that the diffuse reflections from the
surface are scattered with equal intensity in all
directions, independent of viewing direction
ideal diffuse reflectors/Lambertian reflectors
15Diffuse Reflection
- Even though there is equal light scattering in
all directions from a perfect diffuse reflector,
the brightness of the surface does depend on the
orientation of the surface relative to the light
source - Brighter if surface is perpendicular to the
direction of the incident light - Angle of incidence between the incoming light
direction and the surface normal ? - The projected area of a surface patch
perpendicular to the light direction is
proportional to cos?
16Diffuse Reflection
- Thus, the amount of illumination (number of
incident light rays cutting across the surface
patch) depends on cos?
N
A
A cos ?
?
?
Incident light
17Diffuse Reflection
- If the incoming light from the source is
perpendicular to the surface, it is fully
illuminated - A surface is illuminated by a point source only
if the angle of incidence is between 0 and 90
degrees (cos ? in the range 0 to 1) - When ? is negative, the light source is behind
the surface
N
L
q
18Diffuse Reflection
- If N is the unit normal vector to a surface and L
is the unit direction vector to the point light
source from a position on the surface, then cos?
N . L and the diffuse reflection equation for
single point-source illumination is - Il,diff kdIl (N.L)
19Diffuse Reflection
- For general scenes, it is likely that there would
also be some background lighting effects in
addition to that from a direct light source - We can combine the ambient and point-source
intensity calculations to obtain an expression
for the total diffuse reflection - In addition, many graphics packages introduce an
ambient-reflection coefficient ka to modify the
ambient light intensity Ia for each surface,
giving - Idiff ka Ia kd Il (N.L)
- Where both ka and kd depend on surface material
properties and are assigned values in the range 0
to 1
20The Phong Model(Introduction)
- A specular reflection model
N
L
R
?
?
V
?
21Phong Model(Introduction)
- N unit normal vector, R unit vector in the
direction of ideal specular reflection, L unit
vector directed towards the point light source, V
unit vector pointing to the viewer from the
surface position - The specular-reflection angle equals the angle of
incident light (?) - Angle ? is the viewing angle relative to the
specular-reflection direction for R - For an ideal reflector (perfect mirror), incident
light is reflected only in the specular-reflection
direction (Here, where V and R coincide (? 0))
22Phong Model
- If not an ideal reflector, specular reflections
cover a finite range of viewing positions around
vector R shiny surfaces narrow range, dull
surfaces wide range - An empirical model for calculating the
specular-reflection range was developed by Phong
Bui Tuong the Phong Model - Sets the intensity of specular reflection
proportional to cosns ? - Angle can vary between 0 and 90, therefore cos
between 0 and 1 - The value assigned to the specular reflection
parameter ns is determined by the type of surface
to be displayed
23Phong Model
- Shiny surface is modelled with a large value for
ns and similarly for a dull value ns has a small
value - In Phong shading, the normal vectors are
interpolated across the scan line - This results in a higher quality of rendering
highlights are visible on shiny surfaces - Phong shading is not (yet) implemented in
hardware, due to the requirement of floating
points arithmetic
24Light Source Attenuation
- This refers to the fact that two similar objects
illuminated by a light source should have
different intensities depending on the distance
from the light source - As radiant energy from a point light source
travels through space, its amplitude is
attenuated by the factor 1/d2 where d is the
distance the light has travelled - The intensity of light decreases in inverse
proportion to the square of the distance from the
source - A surface close to the light source (small d)
receives a higher incident intensity than a
distant surface (large d) - To produce realistic lighting effects, our
illumination model should take this intensity
attenuation into account
25Attenuation
- A suitable light source attenuation factor is
- fatt 1/Dl2
- where Dl2 is the distance from the point to the
light source - However, this is too drastic, and does not look
realisticIf the light is far away, the function
does not vary very much, if it is close, it
varies greatly - A better approximation is suggested by Rogers,
using a linear attenuation factor - fatt 1/(dK)
- where K is some constant, d is the distance from
the viewer to the object
26Shading Models for Polygons
- We can shade any surface by calculating the
surface normal at each visible point and applying
the desired illumination model - Brute-force shading model expensive
- More efficient shading models for surfaces
defined by polygons and polygon meshes
27Constant Shading Model
- Simplest model (faceted shading/flat shading)
- An illumination model is applied once to
determine a single intensity value then used to
shade the entire polygon - Assume that a scene is illuminated by a distance
point light source and the viewing is from a
distance. - Calculate a single constant surface normal for
each polygon in the polygon mesh representing the
object
28Constant Shading Model
- The result of this is that a faceted appearance
is visible. - Each polygon in the mesh appears distinct
boundaries between adjacent polygons are visible
since two adjacent polygons with different
orientation may have different intensities along
their borders - Curved surfaces (such as spheres) appear very
unrealistic - The simple solution of using a finer mesh is
ineffective, because the perceived difference in
shading between facets is accentuated by the mach
band effect.
29Mach Banding
- The Mach band effect exaggerates the intensity
change at any edge where there is a discontinuity
in magnitude or slope of intensity the dark
facet looks darker, and the light facet looks
lighter - Mach banding is caused by lateral inhibition of
the receptors in the eye. The more light a
receptor receives, the more that receptor
inhibits the response of adjacent receptors - The response of a receptor to light is inhibited
by its adjacent receptors in inverse relation to
the distance to the adjacent receptor - This is known as Mach banding, and can be
overcome by adding more polygons with smaller
intensity changes between them
30Polygon shading models
- So far, the models described determine the shade
of each polygon individually - Two basic shading models take advantage of the
information provided by adjacent polygons to
simulate a smooth surface - Gouraud shading
- Phong shading
31Gouraud Shading
- Also called intensity interpolation shading or
color interpolation shading - It eliminates intensity discontinuities
- Here intensities are calculated at each vertex in
the mesh - The normal at each vertex is required.
- this is performed by averaging the surface
normals of all the polygons for which the vertex
is a member (shared vertices) - The intensity is then calculated at every vertex
of the polygon by applying the appropriate
illumination algorithm - The vertex intensities are linearly interpolated
over the surface of the polygon
32Normal Calculation
33Scan Conversion
34Gouraud Shading
- The result is removal of the intensity
discontinuities present in the Constant Shading
Model - It does, however, have some deficiencies
- Highlights in the surface are sometimes displayed
with anomalous shapes - The linear intensity interpolation can cause
bright or dark intensity streaks (Mach bands) - These effects can be reduced by dividing the
surface into a greater number of polygon faces or
by using other methods, such as Phong shading,
which require more calculations - Gouraud shading is the algorithm most commonly
implemented in hardware (fixed point arithmetic)
35Gouraud Shading
- When averaging surface normals they may turn out
to be parallel (same direction and
intensity)this results in the surface appearing
flat in that area, - .can be solved by introducing additional
polygons (subdividing the original polygons)
before computing the normals - Mach Banding is evident
- No highlights are visible
- unless they coincide with a vertex
36Phong Shading
- More accurate method for rendering a polygon
surface - In Phong shading (normal-vector interpolation
shading), the normal vectors are interpolated
across the scan line and then the illumination
model is applied to each surface point - This results in a higher quality of rendering
highlights are more realistic on shiny surfaces
greatly reduces the Mach band effect - Phong shading is not (yet) implemented in
hardware, due to the requirement of floating
points arithmetic
37Issues
- Number of problems in interpolated shading
models - Perspective Distortion
- Shared Vertices
- Orientation Dependency
- Unrepresentative Vertex Normals
38Perspective Distortion
- Due to the fact that interpolation is performed
in screen space and not world space we have lost
information - As we move from scanline to scanline a constant
incrementing factor is applied - This is inappropriate since although the y-values
may well be simple averages of 2 vertices, the
z-values are unlikely to be this simple (due to
perspective foreshortening) - Result is a (potentially visible)distortion of
the object
39Shared Vertices
- Shading discontinuities can arise whenever there
is a vertex lying along an edge shared by two
polygons and this vertex is not common to the
polygons. - Consider vertex V, lying on edge AB. This vertex
is shared by surfaces S2 and S3, but not S1.
A
S2
S1
V
S3
B
40Shared Vertices
- Shading information determined directly for V
(via surface S1) will typically be different from
that interpolated from A and B via surfaces S2
and S3 - This presents a discontinuity in the shading
- May be overcome by inserting an extra vertex on
surface S1
41Orientation Dependency
- The results of interpolated shading models are
not independent of the orientation of the polygon - Since values are interpolated between vertices
and across horizontal scan lines, the results may
differ when the polygon is rotated
42Orientation Dependency
B
A
P
A
D
B
P
C
D
C
- Interpolated values for P depend (on left) on
values arrived at from AB and AD - Same point on same object (differently oriented)
depends on values arrived at from AB and BC
43Unrepresentative Vertex Normals
- When the averaged normals computed along the
edges are unrepresentative of the component
surfaces comprising the object the resultant
shading values are unsatisfactory - For example, should averaged surface normals
produce vertex normals which are parallel to each
other then there will be little or no variation
in the resultant shading over the polygon (appear
flat shaded)
44Summary
- Illumination models and importance of surface
normals - Three polygon shading models
- flat/constant
- Gouraud
- Phong
- Problems with shading models discussed
- Reading Foley and van Dam Chapter 16