5 1 lighting and shading
play

5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1 - PowerPoint PPT Presentation

Fall 2015 CSCI 420: Computer Graphics 5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1 Debunking Lunar Landing Conspiracies with Global Illumination https://www.youtube.com/watch?v=O9y_AVYMEUs 2 Single Light Source for Global


  1. Fall 2015 CSCI 420: Computer Graphics 5.1 Lighting and Shading Hao Li http://cs420.hao-li.com 1

  2. Debunking Lunar Landing Conspiracies with Global Illumination https://www.youtube.com/watch?v=O9y_AVYMEUs 2

  3. Single Light Source for Global Illumination https://www.youtube.com/watch?v=O9y_AVYMEUs 3

  4. Lighting 4

  5. Outline • Global and Local Illumination • Normal Vectors • Light Sources • Phong Illumination Model 5

  6. Global Illumination • Ray tracing • Radiosity • Photon Mapping Tobias R. Metoc • Follow light rays through a scene • Accurate, but expensive (off-line) 6

  7. Raytracing Example Martin Moeck, Siemens Lighting 7

  8. Radiosity Example Restaurant Interior. Guillermo Leal, Evolucion Visual 8

  9. Local Illumination camera • Approximate model • Local interaction between 
 light source light, surface, viewer • Phong model (this lecture): 
 n fast, supported in OpenGL • GPU shaders • Pixar Renderman (offline) 9

  10. Local Illumination • Approximate model camera • Local interaction between 
 light, surface, viewer light source • Color determined only based on v l surface normal, relative camera n position and relative light position • What effects does this ignore? 10

  11. Outline • Global and Local Illumination • Normal Vectors • Light Sources • Phong Illumination Model 11

  12. Normal Vectors • Must calculate and specify the normal vector - Even in OpenGL! • Two examples: plane and sphere 12

  13. Normals of a Plane, Method I • Method I: given by ax + by + cz + d = 0 • Let be a known point on the plane p 0 • Let be an arbitrary point on the plane p • Recall: if and only if orthogonal to u · v = 0 u v n · ( p − p 0 ) = n · p − n · p 0 = 0 • . c ] T n 0 = [ a b • Consequently n = n 0 • Normalize to | n 0 | 13

  14. Normals of a Plane, Method II • Method II: plane given by p 0 , p 1 , p 2 • Points must not be collinear • Recall: orthogonal to and u × v v u n 0 = ( p 1 − p 0 ) × ( p 2 − p 0 ) • . • Order of cross product determines orientation • Normalize to n = n 0 | n 0 | 14

  15. Normals of Sphere f ( x, y, z ) = x 2 + y 2 + z 2 − 1 = 0 • Implicit Equation • Vector form: f ( p ) = p · p − 1 = 0 • Normal given by gradient vector | n 0 | = 2 p n 0 2 = p • Normalize 15

  16. Reflected Vector • Perfect reflection: angle of incident equals angle of reflection • Also: , , and lie in the same plane l n r • Assume , guarantee | r | = 1 | l | = | n | = 1 l · n = cos( θ ) = n · r r = α l + β n Solution : α = − 1 and β = 2( l · n ) r = 2( l · n ) n − l 16

  17. Outline • Global and Local Illumination • Normal Vectors • Light Sources • Phong Illumination Model 17

  18. Light Sources and Material Properties • Appearance depends on - Light sources, their locations and properties - Material (surface) properties: - Viewer position 18

  19. Types of Light Sources • Ambient light: no identifiable source or direction • Point source: given only by point • Distant light: given only by direction • Spotlight: from source in direction - Cut-off angle defines a cone of light - Attenuation function (brighter in center) 19

  20. Point Source • Given by a point p 0 • Light emitted equally in all directions • Intensity decreases with square of distance 20

  21. Limitations of Point Sources • Shading and shadows inaccurate • Example: penumbra (partial “soft” shadow) • Similar problems with highlights • Compensate with attenuation 1 q = distance | p − p 0 | a + bq + cq 2 a, b, c constants • Softens lighting • Better with ray tracing • Better with radiosity 21

  22. Distant Light Source • Given by a direction vector • Simplifies some calculations • In OpenGL: ⇥ x 1 ⇤ T - Point source y z ⇥ x 0 ⇤ T - Distant source y z 22

  23. Spotlight • Most complex light source in OpenGL • Light still emanates from point • Cut-off by cone determined by angle θ 23

  24. Global Ambient Light • Independent of light source • Lights entire scene • Computationally inexpensive • Simply add to every pixel on 
 [ G R G B ] G G every object • Not very interesting on its own 
 A cheap hack to make the scene brighter 24

  25. Outline • Global and Local Illumination • Normal Vectors • Light Sources • Phong Illumination Model 25

  26. Phong Lighting 26

  27. Phong Illumination Overview • Calculate color for arbitrary point on surface • Compromise between realism and efficiency • Local computation (no visibility calculations) • Basic inputs are material properties and : l, n, v = unit vector to light source l = surface normal n = unit vector to viewer v = reflection of at l p r (determined by and ) l n 27

  28. Phong Illumination Overview [ G R G B ] 1. Start with global ambient light G G 2. Add contributions from each light source 3. Clamp the final result to [0, 1] • Calculate each color channel (R,G,B) separately • Light source contributions decomposed into - Ambient reflection - Diffuse reflection - Specular reflection • Based on ambient, diffuse, and specular lighting and material properties 28

  29. Ambient Reflection I a = k a L a • Intensity of ambient light is uniform at every point • Ambient reflection coefficient k a (material), 0 ≤ k a ≤ 1 • May be different for every surface and r,g,b • Determines reflected fraction of ambient light • L a = ambient component of light source 
 (can be set to different value for each light source) • Note: L a is not a physically meaningful quantity 29

  30. Diffuse Reflection • Diffuse reflector scatters light • Assume equally all direction • Called Lambertian surface • Diffuse reflection coefficient k d (material), 0 ≤ k d ≤ 1 • Angle of incoming light is important 30

  31. Lambert’s Law • Intensity depends on angle of incoming light. 31

  32. Diffuse Light Intensity Depends On Angle Of Incoming Light • Recall = unit vector to light l = unit surface normal n = angle to normal θ cos( θ ) = l · n • . n • . I d = k d L d ( l · n ) θ l • With attenuation: = distance to light source, q = diffuse component of light L d 32

  33. Specular Reflection • Specular reflection coefficient k s (material), 0 ≤ k s ≤ 1 • Shiny surfaces have high specular coefficient • Used to model specular highlights • Does not give mirror effect 
 (need other techniques) specular reflection specular highlights 33

  34. Specular Reflection • Recall = unit vector to camera v = unit reflected vector r φ = angle between and v r n • . cos( φ ) = v · r v φ l • . I s = k s L s (cos φ ) α r • is specular component of light L s • is shininess coefficient α • Can add distance term as well 34

  35. Shininess Coefficient α = 1 • . I s = k s L s (cos φ ) α (cos φ ) α • is the shininess 
 α coefficient φ Higher gives α narrower curves Source: 
 Univ. of Calgary low α high α 35

  36. Summary of Phong Model • Light components for each color: - Ambient ( ), diffuse ( ), specular ( ) L d L a L s • Material coefficients for each color: - Ambient ( ), diffuse ( ), specular ( ) k a k s k d • Distance q for surface point from light source = unit vector to light = reflected about l l r n = surface normal = vector to viewer n v 36

  37. Summary of Phong Model 37

  38. BRDF • Bidirectional Reflection Distribution Function • Must measure for real materials • Isotropic vs. anisotropic • Mathematically complex • Programmable pixel shading Lighting properties of a human face were 
 captured and face re-rendered; Institute for Creative Technologies 38

  39. Summary • Global and Local Illumination • Normal Vectors • Light Sources • Phong Illumination Model 39

  40. http://cs420.hao-li.com Thanks! 40

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend