Document

Shading II
91.427 Computer Graphics I, Fall 2010
1
Objectives
•Continue discussion of shading
•Introduce modified Phong model
•Consider computation of required
vectors
91.427 Computer Graphics I, Fall 2010
2
Ambient Light
•Ambient light = result of multiple
interactions
•between (large) light sources and
objects in environment
•Amount and color depend on both
color of light(s) and material
properties of object
•Add ka Ia to diffuse and specular terms
reflection coef
intensity of ambient light
91.427 Computer Graphics I, Fall 2010
3
Distance Terms
•Light from point source that reaches
surface inversely proportional to square of
distance between them
•Can add factor
fatt = 1/(c1 + c2 d + c3 d2) to
diffuse and specular
terms
•Constant and linear terms soften effect of
point source
•Usually clamp to 1 (take min)
91.427 Computer Graphics I, Fall 2010
4
Light Sources
•In Phong Model, add results from each light
source
•Each light source has separate diffuse,
specular, and ambient terms
•==> allow max flexibility
- even though no physical justification
•Separate R, G, B components
•==> 9 coefficients for each point source
- Idr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab
91.427 Computer Graphics I, Fall 2010
5
Material Properties
•Material properties match light source
properties
- Nine absorption coefficients
• kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab
- Shininess coefficient a
91.427 Computer Graphics I, Fall 2010
6
Adding up the
Components
For each light source and each color
component, Phong model can be
written (without distance terms) as
I = kd Id l · n + ks Is (v · r )a + ka Ia
For each color component
add contributions from
all sources
91.427 Computer Graphics I, Fall 2010
7
Modified Phong Model
•Specular term in Phong model
problematic
•requires for ea. vertex, calculation of
new
reflection vector
view vector
•Blinn suggested approximation
using halfway vector
more efficient
91.427 Computer Graphics I, Fall 2010
8
The Halfway Vector
• h = normalized vector halfway
between l and v
h = ( l + v )/ | l + v |
91.427 Computer Graphics I, Fall 2010
9
Using the halfway vector
•Replace (v · r )a by (n · h )b
• b chosen to match shininess
•Note that halfway angle = half of
angle between r and v if vectors are
coplanar
•Resulting model known as “modified
Phong” or “Blinn lighting model”
- Specified in OpenGL standard
91.427 Computer Graphics I, Fall 2010
10
Example
Only differences in
these teapots are
parameters
in modified
Phong model
91.427 Computer Graphics I, Fall 2010
11
Computation of Vectors
• l and v specified by application
•Can compute r from l and n
•Problem is determining n
•For simple surfaces can be determined
•But how determine n differs
•Depending on underlying rep’n of surface
•OpenGL leaves determination of normal to
application
- Exception for GLU quadrics and Bezier surfaces
(Chapter 11)
91.427 Computer Graphics I, Fall 2010
12
Plane Normals
•Equation of plane: ax + by + cz + d = 0
•From Chapter 4 know that plane
determined by three points p0, p1, p2 or
normal n and p0
•Normal can be obtained by
n = (p2 - p0) × (p1 - p0)
91.427 Computer Graphics I, Fall 2010
13
Computing the cross-product
• v = [v1, v2, v3]T
• w = [w1, w2, w3]T
•
i

v  w = det
 v1
w1
j
v2
w2
k

v3 
w 3 
• Replace i, j, k with e1, e2, e3 ==>
• ==>
v 2 w 3  v 3 w 2 


 v 3 w1  v1w 3 
 v1w 2  v 2 w1 
91.427 Computer Graphics I, Fall 2010
14
Normal to Sphere
•Implicit function f(x, y, z) = 0
•Normal given by gradient
•Sphere f(p) = p · p - 1
• n = [∂f/∂x, ∂f/∂y, ∂f/∂z]T = p
91.427 Computer Graphics I, Fall 2010
15
Parametric Form
•For sphere
x = x(u,v) = cos u sin v
y = y(u,v) = cos u cos v
z = z(u,v) = sin u
• Tangent plane determined by vectors
∂p/∂u = [∂x/∂u, ∂y/∂u, ∂z/∂u]T
∂p/∂v = [∂x/∂v, ∂y/∂v, ∂z/∂v]T
•Normal given by cross product
n = ∂p/∂u × ∂p/∂v
91.427 Computer Graphics I, Fall 2010
16
General Case
•Can compute parametric normals for
other simple cases
- Quadrics
- Parameteric polynomial surfaces
•Bezier surface patches (Chapter 11)
91.427 Computer Graphics I, Fall 2010
17