CS430 Computer Graphics - Winona State University
Download
Report
Transcript CS430 Computer Graphics - Winona State University
CS430
Computer Graphics
Lighting and Shading
Chi-Cheng Lin, Winona State University
Topics
Introduction
Geometric Model in Lighting
Colored Surfaces and Lights
Shading and Graphics Pipeline
Flat Shading and Smooth Shading
2
Introduction
Lighting
Process of computing the luminous
intensity reflected from a specific 3-D point
Shading
Process of assigning colors to pixels
Shading model dictates how light is
scattered or reflected from a surface
We will begin with achromatic light then
colored lights
3
Introduction
Two types of light sources
Point light source
Ambient light
Light interacts surfaces in different ways
Absorbed by surface
Reflected by surface
Transmitted into the interior
What absorbs all of the incident
achromatic light?
4
Introduction
Types of reflection of incident light
Diffuse scattering
Some of the incident light penetrates the
surface slightly and is re-radiated uniformly in all
directions
Scattering light interacts strongly with surface
color is affected by nature of surface material
Specular reflections
Incident light does not penetrate the surface
Reflected directly from the surface
More mirror like and highly directional
Highlight, shiny, plastic like
5
Introduction
Total light reflected from the surface in
a certain direction is the sum of
Diffuse components
Specular components
We calculate the size of each
component that reaches the eye for
each point of interest on surfaces
6
Geometric Model in Lighting
Principle vectors to find amount of light
reaching the eye from a point P
m: normal vector of surface at P
v: from P to the eye
s: from P to light source
s
Angles between vectors are
calculated in the world
coordinates
Is:
m
P
v
eye
intensity of light source
7
Id:
Diffuse Component
intensity of the diffused component
Scattering is uniform in all directions
Independent of v
unless m v 0, where Id = 0 (why?)
Lambert’s law: brightness is proportional
to the area subtended (= fraction cos())
0: brightness varies slightly with angle
90°: brightness falls rapidly to 0
m
s
8
Diffuse Component
ˆ
cos() = ˆs m
I d I s d max(( ˆ
ˆ ), 0 ),
s m
where d diffuse reflection
coefficien t
How do we calculate/obtain the value
for d ? By experiments.
9
Specular Reflection
Isp:
intensity of specular reflection
Phong model is used to approximate
highlight
Amount of light reflected is greatest in the
direction of perfect mirror reflection, r
Amount of light reflected diminished
rapidly at the nearby angles
Beam pattern
r
m
s
P
10
Specular Reflection
ˆ )m
ˆ ?
Remember r s 2 ( s m
Amount of light reflected falls off as
increases and is approximately cosf(),
where f is the Phong exponent
I sp I s s (ˆ
ˆ )f ,
rv
where s specular
s
reflection
r
m
v
coefficien t
eye
Problem: expensive to compute as r has
to be found and normalized
11
Specular Reflection
Solution (proposed by Jim Blinn)
Calculate h = s + v
Let be the angle between h and m
Use to calculate the falloff of specular
intensity as has the same property as
, but can be compensated by different
=0 m =h
value of f
m h
s
s
v
v
ˆ m
I sp I s s max(( h
ˆ ) f ,0 )
12
Ambient Light
A uniform background glow in the
environment
Source is not situated at any particular place
Light spreads uniformly in all directions
Ia:
intensity of light source
Iaa is added to the light reaching the eye
a: ambient reflection coefficient
a is often the same as d
13
Combining Light Contributions
I = Ia a + Id d lambert + Isp s phongf
lambert = max(( ˆs m
ˆ ), 0 )
phong = max(( hˆ m
ˆ ), 0 )
Implications for different points P on a facet
Ambient is not changed for different P
m is the same for all point on the facet
If the light is far far away, s will change slightly
as P changes diffuse will change slightly on
different P
If the light or/and eye is/are close, s and h will
change a lot as P changes specular changes
significantly over the facet
14
Colored Surfaces and Lights
Colored surface
Ir = Iar ar + Idr dr lambert + Ispr sr phongf
Ig = Iag ag + Idg dg lambert + Ispg sg phongf
Ib = Iab ab + Idb db lambert + Ispb sb phongf
lambert and phong terms do not depends on
color component
We have to define 9 reflection coefficients
Ambient and diffuse reflection are based on the
color of surface
15
Colored Surfaces and Lights
Colored light (Isr, Isg, Isb)
If the color of a surface is (r, g, b), then it is
reasonable to set
(ar, ag, ab) = (dr, dg, db) = (rK, gK, bK),
where K is the fraction of light reflected
The diffusion of the surface =
(Isrdr, Isgdg, Isbdb) = (IsrrK, IsggK, IsbbK)
Example: white light
Isr = Isg = Isb = I, (r, g, b) = (0.3, 0.45, 0.25)
then diffusion = (0.3IK, 0.45IK, 0.25IK)
the surface is seen as its color
16
Colored Surfaces and Lights
Color of specular light
Often the same as that of light source
Example: sunlight
Highlight on plastic caused by sunlight is
white
Set (sr, sg, sb) = (s, s, s)
s = 0.5 slightly shiny
s = 0.9 highly shiny
Different coefficients are selected for
specific materials. (Fig 8.17)
17
18
Shading and Graphics Pipeline
Vertices are sent down the pipeline
along with their associated normals
All shading calculations are done on
vertices
v 1 , m1
v2, m2
v 0 , m0
VM
projection
matrix
clip
viewport
matrix
shading is
applied here
19
Shading and Graphics Pipeline
Lights are objects and the positions of
light sources are also transformed by
the modelview matrix
After all quantities are expressed in
camera coordinates, colors are attached
to vertices using the formula
If an object is clipped, normals of newly
generated vertices are calculated by
interpolation
20
Flat Shading and Smooth Shading
Polygonal face in 3D space
Individual face
Underlying surface approximated
Shading methods
Flat shading
Smooth shading
Gouraud shading
Phong shading
21
Comparison of Shading Methods
22
Flat Shading
Entire face is drawn with the same color
Lateral inhibition
When there is a discontinuity across an
object, the eye manufactures a Mach band
at the discontinuity and a vivid edge is seen
Specular highlights are rendered poorly
Either no highlight at all
Or highlight on the entire face
23
Smooth Shading
Smooth shading computes colors at more
points on each face to de-emphasize
edges between adjacent faces
Use linear interpolation
Gouraud shading
Interpolate vertex colors
Phong shading
Interpolate vertex normals
Interpolate normal for each pixel
24
Gouraud Shading
Used by OpenGL
Example
color3
colora: by interpolating
color2
color3 and color4 colora
colorb
colorb: by interpolating color
4
color1
color1 and color2
Colors of pixels on the horizontal line
segment is obtained by interpolating
colora and colorb
Does not picture highlights well
25
Phong Shading
Compute normal at each pixel by
interpolating the normals at the vertices
Apply the shading model to to every
point to find the color
Example
m3
ma: by interpolating m3 and m4
mb: by interpolating m1 and m2
m2
Normals of pixels on the
ma
mb
horizontal line segment is
m4
m1
obtained by interpolating ma and mb
Colors of the pixels are then computed
26
Phong Shading
Very smooth appearance
Highlights are approximated better
Principle drawback
Heavy computation slow speed
Not supported by OpenGL
Can be approximated using texture
mapping
Phong shading Phong model
Don’t be
confused!!
27