cs 543 computer graphics illumination and shading i
play

CS 543 - Computer Graphics: Illumination and Shading I by Robert - PDF document

CS 543 - Computer Graphics: Illumination and Shading I by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Illumination and Shading Problem: Model light/surface point interactions to determine final color and brightness


  1. CS 543 - Computer Graphics: Illumination and Shading I by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Illumination and Shading  Problem: Model light/surface point interactions to determine final color and brightness  Apply the lighting model at a set of points across the entire surface lighting Shading R.W. Lindeman - WPI Dept. of Computer Science 2 1

  2. Illumination Model  The governing principles for computing the illumination  An illumination model usually considers  Light attributes (intensity, color, position, direction, shape)  Object surface attributes (color, reflectivity, transparency, etc. )  Interaction among lights and objects R.W. Lindeman - WPI Dept. of Computer Science 3 Basic Light Sources  Light intensity can be independent or dependent of the distance between object and the light source Point light Spot light Area light Directional light R.W. Lindeman - WPI Dept. of Computer Science 4 2

  3. Local Illumination  Only consider the light, the observer position, and the object material properties  OpenGL does this θ R.W. Lindeman - WPI Dept. of Computer Science 5 Global Illumination  Take into account the interaction of light from all the surfaces in the scene  Example:  Ray Tracing  Model light rays bouncing around object 4 object 3 object 2 object 1 R.W. Lindeman - WPI Dept. of Computer Science 6 3

  4. Global Illumination (cont.)  Example:  Radiosity  Model energy moving from emitters (e.g., lights) into the scene  View independent R.W. Lindeman - WPI Dept. of Computer Science 7 Simple Local Illumination  The model used by OpenGL  Reduce the complex workings of light to three components  Ambient  Diffuse  Specular  Final illumination at a point (vertex) = ambient + diffuse + specular  Materials reflect each component differently  Use different material reflection coefficients  K a , K d , K s R.W. Lindeman - WPI Dept. of Computer Science 8 4

  5. Ambient Light Contribution  Ambient light = background light  Light that is scattered by the environment  It's just there  Frequently assumed to be constant  Very simple approximation of global illumination  No direction: independent of light position, object orientation, observer’s position/orientation object 4 constant object 3 object 2 Ambient = I x K a object 1 R.W. Lindeman - WPI Dept. of Computer Science 9 Diffuse Light Contribution  Diffuse light: The illumination that a surface receives from a light source that reflects equally in all direction  Eye point does not matter R.W. Lindeman - WPI Dept. of Computer Science 10 5

  6. Diffuse Light Calculation  Need to decide how much light the object point receives from the light source  Based on Lambert’s Law Receive more light Receive less light R.W. Lindeman - WPI Dept. of Computer Science 11 Diffuse Light Calculation (cont.)  Lambert’s law: the radiant energy D that a small surface patch receives from a light source is: Diffuse = K d x I x cos( θ ) K d : diffuse reflection coefficient I: light intensity θ : angle between the light vector and the surface normal light vector (vector from object to light) θ N : surface normal R.W. Lindeman - WPI Dept. of Computer Science 12 6

  7. Diffuse Light Examples I = 1.0 K d = 0 .0 0 .2 0 .4 0 .6 0 .8 1 .0 R.W. Lindeman - WPI Dept. of Computer Science 13 Specular Light Contribution  The bright spot on the object  The result of total reflection of the incident light in a concentrate region Sees lots of Sees no specular specular R.W. Lindeman - WPI Dept. of Computer Science 14 7

  8. Specular Light Calculation  How much reflection you can see depends on where you are  But for non-perfect surface you will still see specular highlight when you move a little bit away from the ideal reflection direction Φ is deviation of view angle from mirror direction  When φ is small, you see more specular highlight R.W. Lindeman - WPI Dept. of Computer Science 15 Specular Light Calculation (cont.)  Phong lighting model Specular = K s x I x cos f ( φ )  Not Phong shading model  The effect of 'f' in the Phong model f = 10 f = 90 f = 30 f = 270 R.W. Lindeman - WPI Dept. of Computer Science 16 8

  9. Specular Light Examples K s = 0 .25 K s = 0 .5 K s = 0 .75 f = 3 f = 6 f = 9 f = 25 f = 200 R.W. Lindeman - WPI Dept. of Computer Science 17 Putting It All Together  Illumination from a light Illum = ambient + diffuse + specular = K a x I + K d x I x cos( θ ) + K s x I x cos f ( φ )  If there are N lights Total illumination for a point P = Σ (Illum)  Some more terms to be added (in OpenGL)  Self emission  Global ambient  Light distance attenuation and spot light effect R.W. Lindeman - WPI Dept. of Computer Science 18 9

  10. Putting It All Together (cont.)  Illum = ambient + diffuse + specular R.W. Lindeman - WPI Dept. of Computer Science 19 Ambient Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 20 10

  11. Diffuse Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 21 Specular Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 22 11

  12. Adding Color  Sometimes light or surfaces are colored  Treat R,G and B components separately  i.e. , can specify different RGB values for either light or material  Illumination equation goes from Illum = ambient + diffuse + specular = K a x I + K d x I x cos( θ ) + K s x I x cos f ( φ ) To: Illum r = K ar x I r + K dr x I r x cos( θ ) + K sr x I r x cos f ( φ ) Illum g = K ag x I g + K dg x I g x cos( θ ) + K sg x I g x cos f ( φ ) Illum b = K ab x I b + K db x I b x cos( θ ) + K sb x I b x cos f ( φ ) R.W. Lindeman - WPI Dept. of Computer Science 23 Adding Color (cont.) Material Ambient Diffuse Specular Exponent f K ar , K ag , K ab K dr , K dg , K db K sr , K sg , K sb Black 0.0 0.01 0.5 32 plastic 0.0 0.01 0.5 0.0 0.01 0.5 Brass 0.329412 0.780392 0.992157 27.8974 0.223529 0.568627 0.941176 0.027451 0.113725 0.807843 Polished 0.23125 0.2775 0.773911 89.6 Silver 0.23125 0.2775 0.773911 0.23125 0.2775 0.773911  (excerpt from Hill, Fig. 8.17) R.W. Lindeman - WPI Dept. of Computer Science 24 12

  13. Lighting in OpenGL  Adopt Phong lighting model  Ambient + Specular + Diffuse lights  Lighting is computed at vertices  Interpolate across surface (Gouraud/smooth shading)  Setting up OpenGL lighting  Light properties  Enable/disable lighting  Surface material properties  Provide correct surface normals  Set light model properties R.W. Lindeman - WPI Dept. of Computer Science 25 Light Properties Properties  Colors / Position and type / attenuation  glLightfv( light, property, value ) 1 3 2 (1) Constant: specify which light you want to set the property for e.g., GL_LIGHT0, GL_LIGHT1, GL_LIGHT2 ... you can create multiple lights (OpenGL allows at least 8 lights) (2) Constant: specify which light property you want to set e.g., GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION (check the red book, or the Web, for more) (3) The value you want to set to the property R.W. Lindeman - WPI Dept. of Computer Science 26 13

  14. Property Example  Define colors and position a light GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; Colors GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; Position GLfloat light_position[] = { 0.0, 0.0, 1.0, 1.0 }; What if I set glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient ); Position to glLightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse ); (0, 0, 1, 0)? glLightfv( GL_LIGHT0, GL_SPECULAR, light_specular ); glLightfv( GL_LIGHT0, GL_POSITION, light_position ); R.W. Lindeman - WPI Dept. of Computer Science 27 Types of Lights  OpenGL supports two types of lights  Local light (point light)  Infinite light (directional light)  Determined by the light positions you provide  w = 0: Infinite light source  w != 0:Point light  Position = (x/w, y/w, z/w) GLfloat light_position[] = { x, y, z, w }; glLightfv( GL_LIGHT0, GL_POSITION, light_position ); R.W. Lindeman - WPI Dept. of Computer Science 28 14

  15. Turning on the Lights  Turn on/off the power (for all the lights)  glEnable( GL_LIGHTING );  glDisable( GL_LIGHTING );  Turn on each light switch  glEnable( GL_LIGHT n ) ( n = 0, 1, 2, ...) R.W. Lindeman - WPI Dept. of Computer Science 29 Controlling Light Position  Modelview matrix affects a light’s position  Two options  Option a:  Treat light like vertex  Do pushMatrix , translate , rotate , ... glLightfv POSITION , popMatrix  Then call gluLookAt  Light moves independently of camera  Option b:  Load identity matrix in modelview matrix  Call glLightfv then call gluLookAt  Light appears at the eye (like a miner’s lamp) R.W. Lindeman - WPI Dept. of Computer Science 30 15

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