Today Illumination Shading 1 million triangles drawn with 1 color per triangle Determining an Object s Appearance Ultimately we re interested in modeling light transport in scene Light is emitted from light sources and interacts with surfaces on impact with an object some is reflected and some is absorbed distribution of reflected light determines finish matte glossy composition of light arriving at eye determines what we see Let s focus on the local interaction of light with single surface point Incident light Reflected light Some reaches eye Some light is absorbed 1 Modeling Light Sources In general light sources have a very complex structure incandescent light bulbs the sun CRT monitors To simplify things we ll focus on point light sources for now light source is a single infinitesimal point emits light equally in all directions isotropic illumination outgoing light is set of rays originating at light point Creating lights in OpenGL glEnable GL LIGHTING turn on lighting of objects glEnable GL LIGHT0 turn on specific light glLight specify position emitted light intensity Basic Local Illumination Model We re only interested in light that finally arrives at view point a function of the light viewing positions and local surface reflectance n L Characterize light using RGB triples can operate on each channel separately v Given a point compute intensity of reflected light 2 Diffuse Reflection This is the simplest kind of reflection also called Lambertian reflection models dull matte surfaces materials like chalk Ideal diffuse reflection scatters incoming light equally in all directions identical appearance from all viewing directions reflected intensity depends only on direction of light source Light is reflected according to Lambert s Law Lambert s Law for Diffuse Reflection Purely diffuse object I d I L kd max cos 0 I L kd max n L 0 n L I d resulting intensity diffuse I L light source intensity kd diffuse surface reflectance coefficient kd 0 1 angle between normal light direction 3 Specular Reflection Diffuse reflection is nice but many surfaces are shiny their appearance changes as the viewpoint moves they have glossy specular highlights or specularities because they reflect light coherently in a preferred direction A mirror is a perfect specular reflector incoming ray reflected about normal direction nothing reflected in any other direction Most surfaces are imperfect specular reflectors reflect rays in cone about perfect reflection direction Phong Specular Illumination Model I s I L ks max cos 0 n I L ks max r v 0 n L n r One particular specular reflection model quite common in practice it is purely empirical there s no physical basis for it I s resulting intensity specular v I L light source intensity ks specular surface reflectance coefficient ks 0 1 angle between viewing reflection direction n shininess factor 4 Examples of Phong Specular Model Diffuse only Diffuse Specular shininess 5 Diffuse Specular shininess 50 The Ambient Glow So far areas not directly illuminated by any light appear black this tends to look rather unnatural in the real world there s lots of ambient light To compensate we invent new light source assume there is a constant ambient glow this ambient glow is purely fictitious Just add in another term to our illumination equation I I d I s I a ka I a ambient light intensity ka ambient surface reflectance coefficient 5 Our Three Basic Components of Illumination Diffuse I Id Specular I Is Ambient I I a ka Combined for the Final Result I I d I s I a ka 6 Recall How to Color Polygons Hard coded colors on surface of model maybe from pre computed illumination e g radiosity explicitly specify 1 color per face vertex Flat Shaded Smooth Shaded glBegin GL TRIANGLES for int j 0 j n j glColor3fv c glVertex3fv v1 glVertex3fv v2 glVertex3fv v3 glEnd glBegin GL TRIANGLES for int j 0 j n j glColor3fv c1 glVertex3fv v1 glColor3fv c2 glVertex3fv v2 glColor3fv c3 glVertex3fv v3 glEnd Drawing Polygons with Lighting We usually want OpenGL to infer colors via illumination model specify 1 normal per face vertex Flat Shaded Smooth Shaded glBegin GL TRIANGLES for int j 0 j n j glNormal3fv n glVertex3fv v1 glVertex3fv v2 glVertex3fv v3 glEnd glBegin GL TRIANGLES for int j 0 j n j glNormal3fv n1 glVertex3fv v1 glNormal3fv n2 glVertex3fv v2 glNormal3fv n3 glVertex3fv v3 glEnd 7 Shading Polygons Flat Shading Illumination equations are evaluated at surface locations so where do we apply them We could just do it once per polygon fill every pixel covered by polygon with the resulting color OpenGL glShadeModel GL FLAT Shading Polygons Gouraud Shading Alternatively we could evaluate at every vertex linearly interpolate color along edges linearly interpolate along scan lines interpolation in screen space varies with viewpoint Misses details that don t fall on vertex specular highlights for instance OpenGL glShadeModel GL SMOOTH 8 Shading Polygons Phong Shading Don t just interpolate colors over polygons Interpolate surface normal over polygon evaluate illumination equation at each pixel OpenGL not supported Defining Materials in OpenGL Just like everything else there is a current material specifies the reflectances of the objects being drawn reflectances e g kd are RGB triples Set current values with glMaterial GLfloat tan 0 8 0 7 0 3 1 0 GLfloat tan2 0 4 0 35 0 15 1 0 glMaterialfv GL FRONT AND BACK GL AMBIENT tan glMaterialfv GL FRONT AND BACK GL DIFFUSE tan glMaterialfv GL FRONT AND BACK GL SPECULAR tan2 glMaterialf GL FRONT AND BACK GL SHININESS 50 0 9 Defining Lights in OpenGL A fixed set of lights are available at least 8 turn them on with glEnable GL LIGHTx set their values with glLight GLfloat white 1 0 1 0 1 0 1 0 GLfloat p 2 0 3 0 10 0 1 0 w 0 for directional light glEnable GL LIGHTING glEnable GL LIGHT0 glLightModeli GL LIGHT MODEL TWO SIDE GL TRUE glLightfv GL LIGHT0 GL POSITION p glLightfv GL LIGHT0 GL DIFFUSE white glLightfv GL LIGHT0 GL SPECULAR white can be different glEnable GL NORMALIZE guarantee unit normals Summarizing the Shading Model We describe local appearance with illumination equations consists of a sum of set of components light is additive treat each wavelength independently currently diffuse specular and ambient terms I I L kd max cos 0 I L ks max cos 0 n I a ka Must shade every pixel covered by polygon flat shading constant color Gouraud shading interpolate corner colors Phong shading interpolate corner normals L n r v 10 What Have We Ignored Some local
View Full Document
Unlocking...