Download presentation
Presentation is loading. Please wait.
Published byRegina Wells Modified over 8 years ago
1
Lighting and Reflection Angel 6.1-6.3 Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 1
2
Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build a simple reflection model---the Phong model--- that can be used with real time graphics hardware Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 2
3
Why we need shading Suppose we build a model of a sphere using many polygons and color it with glColor. We get something like But we want Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 3
4
Shading Why does the image of a real sphere look like Light-material interactions cause each point to have a different color or shade Need to consider –Light sources –Material properties –Location of viewer –Surface orientation Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 4
5
Scattering Light strikes A –Some scattered –Some absorbed Some of scattered light strikes B –Some scattered –Some absorbed Some of this scattered light strikes A and so on Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 5
6
Rendering Equation The infinite scattering and absorption of light can be described by the rendering equation –Cannot be solved in general –Ray tracing is a special case for perfectly reflecting surfaces Rendering equation is global and includes –Shadows –Multiple scattering from object to object Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 6
7
Global Effects Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 7 translucent surface shadow multiple reflection
8
Local vs Global Rendering Correct shading requires a global calculation involving all objects and light sources –Incompatible with pipeline model which shades each polygon independently (local rendering) However, in computer graphics, especially real time graphics, we are happy if things “look right” –Many techniques for approximating global effects exist Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 8
9
Light-Material Interaction Light that strikes an object is partially absorbed and partially scattered (reflected) The amount reflected determines the color and brightness of the object –A surface appears red under white light because the red component of the light is reflected and the rest is absorbed The reflected light is scattered in a manner that depends on the smoothness and orientation of the surface Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 9
10
Bidirectional Reflection Distribution Function (BDRF) Five variables –Two input angles –Two output angles –Frequency of light Difficult to compute in real time Thus we approximate with other models –Additive of diffuse, specular, ambient –Transmission if needed Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 10
11
Light Source Illumination function –Point of origin (x,y,z) –Wavelength ( ) –Direction of emission ( , ) Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 11
12
Light Sources General light sources are difficult to work with because we must integrate light coming from all points on the source Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 12
13
Simple Light Sources Ambient light –Same amount of light everywhere in scene –Can model contribution of many sources and reflecting surfaces Point source –Model with position and color –Distant source = infinite distance away (parallel) Spotlight –Restrict light from ideal point source Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 13
14
Color Sources Reduce to just 3 tristimulus factors RGB L = (L r, L g, L b ) Future equations expressed via L where L {L r, L g, L b } Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 14
15
Ambient Light Applies light to all spaces within the scene –Without it, everything would be dark (unless self-emitting) Uniform light Components RGB –L ar, L ag, L ab OpenGL allows us to specify ambient Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 15
16
Ambient Light Ambient light is the result of multiple interactions between (large) light sources and the objects in the environment Amount and color depend on both the color of the light(s) and the material properties of the object Add k a I a to diffuse and specular terms Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 16 reflection coef intensity of ambient light
17
Point Source Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 17 Light in all directions Proportional to inverse square We can add a factor of the form 1/(a + bd +cd 2 ) The constant and linear terms soften the effect of the point source
18
Spotlight Point source P s Pointing in direction of l s Cone width of –If = 180, this is point source More realistic spotlights adjust intensity as we move from center –Typically cos e Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 18
19
Distant Light Sources Homogeneous systems Point vs. vector Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 19
20
Surface Types The smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the light A very rough surface scatters light in all directions Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 20 smooth surface Rough/diffuse surface
21
Phong Model A simple model that can be computed rapidly Has three components –Ambient ( I a ) –Diffuse ( I d ) –Specular ( I s ) Uses four vectors –To source (l) –To viewer (v) –Normal (n) –Perfect reflector (r) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 21
22
Phong: Ambient Ambient intensity ( I a ) same at every point on surface Amount not absorbed is ambient reflection coefficient (k a ) I a = k a L a Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 22
23
Ideal Reflector Normal is determined by local orientation Angle of incidence = angle of relection The three vectors must be coplanar Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 23 r = 2 (l · n ) n - l
24
Lambertian Surface Perfectly diffuse reflector Light scattered equally in all directions Amount of light reflected is proportional to the vertical component of incoming light –reflected light ~ cos i – cos i = l · n if vectors normalized –There are also three coefficients, k r, k b, k g that show how much of each color component is reflected Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 24
25
Phong: Diffuse Reflection Only see vertical component of light As u is lowered, same amount of light is spread across broader area Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 25 I d = k d (l n)L d
26
Specular Surfaces Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors) Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 26 specular highlight
27
Modeling Specular Relections Phong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increased Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 27 I s = k s L s cos shininess coef absorption coef incoming intensity reflected intensity
28
The Shininess Coefficient Values of between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plastic Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 28 cos 90 -90
29
Vectors, Normals, & Shading Angel 6.4-6.5 Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 29
30
Objectives Discuss vectors & normals Introduce the OpenGL shading functions Discuss polygonal shading –Flat –Smooth –Gouraud Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 30
31
Steps in OpenGL shading Enable shading and select model Specify normals Specify material properties Specify lights Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 31
32
Normal for Triangle Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 32 p0p0 p1p1 p2p2 n plane n ·(p - p 0 ) = 0 n = (p 2 - p 0 ) ×(p 1 - p 0 ) normalize n n/ |n| p Note that right-hand rule determines outward face
33
Normals and Gradients For a non-linear surface, we can find the plane where the normal to this plane is the gradient. Doing this many times across the surface allows us to do shading… Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 33 n p
34
Normals In OpenGL the normal vector is part of the state Set by glNormal*() – glNormal3f(x, y, z); – glNormal3fv(p); Usually we want to set the normal to have unit length so cosine calculations are correct –Length can be affected by transformations –Note that scaling does not preserved length – glEnable(GL_NORMALIZE) allows for autonormalization at a performance penalty Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 34
35
Enabling Shading Shading calculations are enabled by – glEnable(GL_LIGHTING) –Once lighting is enabled, glColor() ignored Must enable each light source individually – glEnable(GL_LIGHTi) i=0,1….. Can choose light model parameters – glLightModeli(parameter, GL_TRUE) GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 35
36
Polygonal Shading Shading calculations are done for each vertex –Vertex colors become vertex shades By default, vertex shades are interpolated across the polygon – glShadeModel(GL_SMOOTH); If we use glShadeModel(GL_FLAT); the color at the first vertex will determine the shade of the whole polygon Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 36
37
Polygon Normals Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 37 Polygons have a single normal –Shades at the vertices as computed by the Phong model can be almost same –Identical for a distant viewer (default) or if there is no specular component Consider model of sphere Want different normals at each vertex even though this concept is not quite correct mathematically
38
Smooth Shading Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 38 We can set a new normal at each vertex Easy for sphere model –If centered at origin n = p Now smooth shading works Note silhouette edge
39
Mesh Shading The previous example is not general because we knew the normal at each vertex analytically For polygonal models, Gouraud proposed we use the average of the normals around a mesh vertex Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 39 n = (n 1 +n 2 +n 3 +n 4 )/ |n 1 +n 2 +n 3 +n 4 |
40
Gouraud and Phong Shading Gouraud Shading –Find average normal at each vertex (vertex normals) –Apply modified Phong model at each vertex –Interpolate vertex shades across each polygon Phong shading –Find vertex normals –Interpolate vertex normals across edges –Interpolate edge normals across polygon –Apply modified Phong model at each fragment Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 40
41
Comparison If the polygon mesh approximates surfaces with a high curvatures, Phong shading may look smooth while Gouraud shading may show edges Phong shading requires much more work than Gouraud shading –Until recently not available in real time systems –Now can be done using fragment shaders (see Chapter 9) Both need data structures to represent meshes so we can obtain vertex normals Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 41
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.