# 1 91.427 Computer Graphics I, Fall 2010 Shading II.

## Presentation on theme: "1 91.427 Computer Graphics I, Fall 2010 Shading II."— Presentation transcript:

1 91.427 Computer Graphics I, Fall 2010 Shading II

2 91.427 Computer Graphics I, Fall 2010 Objectives Continue discussion of shading Introduce modified Phong model Consider computation of required vectors

3 91.427 Computer Graphics I, Fall 2010 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 k a I a to diffuse and specular terms reflection coef intensity of ambient light

4 91.427 Computer Graphics I, Fall 2010 Distance Terms Light from point source that reaches surface inversely proportional to square of distance between them Can add factor f att = 1/(c 1 + c 2 d + c 3 d 2 ) to diffuse and specular terms Constant and linear terms soften effect of point source Usually clamp to 1 (take min)

5 91.427 Computer Graphics I, Fall 2010 Light Sources In Phong Model, add results from each light source Each light source has separate d iffuse, s pecular, and a mbient terms ==> allow max flexibility ­even though no physical justification Separate R, G, B components ==> 9 coefficients for each point source ­I dr, I dg, I db, I sr, I sg, I sb, I ar, I ag, I ab

6 91.427 Computer Graphics I, Fall 2010 Material Properties Material properties match light source properties ­Nine absorption coefficients k dr, k dg, k db, k sr, k sg, k sb, k ar, k ag, k ab ­Shininess coefficient 

7 91.427 Computer Graphics I, Fall 2010 Adding up the Components For each light source and each color component, Phong model can be written (without distance terms) as I = k d I d l · n + k s I s ( v · r )  + k a I a For each color component add contributions from all sources

8 91.427 Computer Graphics I, Fall 2010 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

9 91.427 Computer Graphics I, Fall 2010 The Halfway Vector h = normalized vector halfway between l and v h = ( l + v )/ | l + v |

10 91.427 Computer Graphics I, Fall 2010 Using the halfway vector Replace ( v · r )  by ( n · h )   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

11 91.427 Computer Graphics I, Fall 2010 Example Only differences in these teapots are parameters in modified Phong model

12 91.427 Computer Graphics I, Fall 2010 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)

13 91.427 Computer Graphics I, Fall 2010 Plane Normals Equation of plane: ax + by + cz + d = 0 From Chapter 4 know that plane determined by three points p 0, p 1, p 2 or normal n and p 0 Normal can be obtained by n = (p 2 - p 0 ) × (p 1 - p 0 )

14 91.427 Computer Graphics I, Fall 2010 Computing the cross-product v = [v 1, v 2, v 3 ] T w = [w 1, w 2, w 3 ] T v  w = det Replace i, j, k with e 1, e 2, e 3 ==> ==>

15 91.427 Computer Graphics I, Fall 2010 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

16 91.427 Computer Graphics I, Fall 2010 Parametric Form For sphere Tangent plane determined by vectors Normal given by cross product x = x(u,v) = cos u sin v y = y(u,v) = cos u cos v z = z(u,v) = sin u ∂p/∂u = [∂x/∂u, ∂y/∂u, ∂z/∂u] T ∂p/∂v = [∂x/∂v, ∂y/∂v, ∂z/∂v] T n = ∂p/∂u × ∂p/∂v

17 91.427 Computer Graphics I, Fall 2010 General Case Can compute parametric normals for other simple cases ­Quadrics ­Parameteric polynomial surfaces Bezier surface patches (Chapter 11)