Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading.

Similar presentations


Presentation on theme: "Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading."— Presentation transcript:

1 Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading

2 2 Topics l Introduction l Geometric Model in Lighting l Colored Surfaces and Lights l Shading and Graphics Pipeline l Flat Shading and Smooth Shading

3 3 Introduction l Lighting zProcess of computing the luminous intensity reflected from a specific 3-D point l Shading zProcess of assigning colors to pixels l Shading model dictates how light is scattered or reflected from a surface zWe will begin with achromatic light then colored lights

4 4 Introduction l Two types of light sources zPoint light source zAmbient light l Light interacts surfaces in different ways zAbsorbed by surface zReflected by surface zTransmitted into the interior l What absorbs all of the incident achromatic light?

5 5 Introduction l Types of reflection of incident light zDiffuse scattering ySome of the incident light penetrates the surface slightly and is re-radiated uniformly in all directions yScattering light interacts strongly with surface  color is affected by nature of surface material zSpecular reflections yIncident light does not penetrate the surface yReflected directly from the surface yMore mirror like and highly directional yHighlight, shiny, plastic like

6 6 Introduction l Total light reflected from the surface in a certain direction is the sum of zDiffuse components zSpecular components l We calculate the size of each component that reaches the eye for each point of interest on surfaces

7 7 Geometric Model in Lighting l Principle vectors to find amount of light reaching the eye from a point P zm: normal vector of surface at P zv: from P to the eye zs: from P to light source zAngles between vectors are calculated in the world coordinates l I s : intensity of light source m v s P eye

8 8 Diffuse Component l I d : intensity of the diffused component zScattering is uniform in all directions zIndependent of v yunless m  v  0, where I d = 0 (why?) l Lambert’s law: brightness is proportional to the area subtended (= fraction cos(  )) z   0: brightness varies slightly with angle z   90°: brightness falls rapidly to 0 m s 

9 9 Diffuse Component l cos(  ) = l l How do we calculate/obtain the value for  d ? By experiments.

10 10 Specular Reflection l I sp : intensity of specular reflection l Phong model is used to approximate highlight zAmount of light reflected is greatest in the direction of perfect mirror reflection, r zAmount of light reflected diminished rapidly at the nearby angles zBeam pattern m s P r

11 11 Specular Reflection l Remember ? l Amount of light reflected falls off as  increases and is approximately cos f (  ), where f is the Phong exponent l l Problem: expensive to compute as r has to be found and normalized m v s eye r 

12 12 Specular Reflection l Solution (proposed by Jim Blinn) zCalculate h = s + v zLet  be the angle between h and m zUse  to calculate the falloff of specular intensity as  has the same property as  z   , but can be compensated by different value of f l m v s h  m v s =h=h  =0

13 13 Ambient Light l A uniform background glow in the environment zSource is not situated at any particular place zLight spreads uniformly in all directions l I a : intensity of light source l I a  a is added to the light reaching the eye z  a : ambient reflection coefficient z  a is often the same as  d

14 14 Combining Light Contributions l I = I a  a + I d  d  lambert + I sp  s  phong f zlambert = zphong = l Implications for different points P on a facet zAmbient is not changed for different P zm is the same for all point on the facet zIf the light is far far away, s will change slightly as P changes  diffuse will change slightly on different P zIf the light or/and eye is/are close, s and h will change a lot as P changes  specular changes significantly over the facet

15 15 Colored Surfaces and Lights l Colored surface zI r = I ar  ar + I dr  dr  lambert + I spr  sr  phong f zI g = I ag  ag + I dg  dg  lambert + I spg  sg  phong f zI b = I ab  ab + I db  db  lambert + I spb  sb  phong f l lambert and phong terms do not depends on color component l We have to define 9 reflection coefficients zAmbient and diffuse reflection are based on the color of surface

16 16 Colored Surfaces and Lights l Colored light (I sr, I sg, I sb ) zIf 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 zThe diffusion of the surface = (I sr  dr, I sg  dg, I sb  db ) = (I sr rK, I sg gK, I sb bK) l Example: white light zI sr = I sg = I sb = 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

17 17 Colored Surfaces and Lights l Color of specular light zOften the same as that of light source l Example: sunlight zHighlight on plastic caused by sunlight is white zSet (  sr,  sg,  sb ) = (  s,  s,  s ) y  s = 0.5  slightly shiny y  s = 0.9  highly shiny l Different coefficients are selected for specific materials. (Fig 8.17)

18 18

19 19 Shading and Graphics Pipeline l Vertices are sent down the pipeline along with their associated normals l All shading calculations are done on vertices VM clip projection matrix viewport matrix shading is applied here v 1, m 1 v 2, m 2 v 0, m 0

20 20 Shading and Graphics Pipeline l Lights are objects and the positions of light sources are also transformed by the modelview matrix l After all quantities are expressed in camera coordinates, colors are attached to vertices using the formula l If an object is clipped, normals of newly generated vertices are calculated by interpolation

21 21 Flat Shading and Smooth Shading l Polygonal face in 3D space zIndividual face zUnderlying surface approximated l Shading methods zFlat shading zSmooth shading yGouraud shading yPhong shading

22 22 Comparison of Shading Methods

23 23 Flat Shading l Entire face is drawn with the same color l Lateral inhibition zWhen there is a discontinuity across an object, the eye manufactures a Mach band at the discontinuity and a vivid edge is seen l Specular highlights are rendered poorly zEither no highlight at all zOr highlight on the entire face

24 24 Smooth Shading l Smooth shading computes colors at more points on each face to de-emphasize edges between adjacent faces l Use linear interpolation l Gouraud shading zInterpolate vertex colors l Phong shading zInterpolate vertex normals zInterpolate normal for each pixel

25 25 Gouraud Shading l Used by OpenGL l Example zcolor a : by interpolating color 3 and color 4 zcolor b : by interpolating color 1 and color 2 zColors of pixels on the horizontal line segment is obtained by interpolating color a and color b l Does not picture highlights well color 1 color 2 color 3 color 4 color a color b

26 26 Phong Shading l Compute normal at each pixel by interpolating the normals at the vertices l Apply the shading model to to every point to find the color l Example zm a : by interpolating m 3 and m 4 zm b : by interpolating m 1 and m 2 zNormals of pixels on the horizontal line segment is obtained by interpolating m a and m b zColors of the pixels are then computed m1m1 m2m2 m3m3 m4m4 mama mbmb

27 27 Phong Shading l Very smooth appearance l Highlights are approximated better l Principle drawback zHeavy computation  slow speed l Not supported by OpenGL zCan be approximated using texture mapping l Phong shading  Phong model Don’t be confused!!


Download ppt "Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading."

Similar presentations


Ads by Google