We Need More General Cameras So far we ve assumed a canonical camera configuration focal point at the origin image plane parallel to xy plane This is pretty limited we want greater flexibility deriving general projection matrices is painful but we can transform world so camera is canonical typically called the viewing transformation Naturally there are several ways of setting this up we ll focus on the OpenGL supported mechanism Specifying General Camera Configurations First we want to allow focal point to be anywhere in space call this position lookFrom or just from Next we need to specify the orientation of the camera define what it s pointing at lookAt lookAt lookFrom will define the axis of projection define vertical axis of image vUp essentially a twist parameter about the lookAt axis 1 Converting Camera to Canonical Form Our camera is parameterized by three vectors lookFrom lookAt and vUp We want to transform into canonical camera position 1 translate lookFrom to the origin translate by lookFrom 2 rotate lookAt lookFrom to the z axis Axis u lookAt lookFrom z Angle sin 1 u L where L lookAt lookFrom z 3 rotate about z so that vUp lies inside the y z plane OpenGL Transformation Matrices OpenGL maintains two different matrices one to hold the camera projection matrix and one to hold everything else select current matrix with glMatrixMode which which is GL MODELVIEW or GL PROJECTION glFrustum and friends multiply the current matrix just like glTranslate glScale glRotate Vertices are transformed in the following manner Model view Projection Perspective division 2 OpenGL Viewing Transformations Specify camera configuration with gluLookAt ex ey ez ax ay az ux uy uz These are our three camera vectors lookFrom ex ey ez lookAt ax ay az vUp ux uy uz Typical Transformation Setup glMatrixMode GL PROJECTION glLoadIdentity gluPerspective fovy aspect zNear zFar glMatrixMode GL MODELVIEW glLoadIdentity gluLookat ex ey ez ax ay az 0 1 0 Demo See Links web page for link to OpenGL tutors 3 Multi Perspective Projections A Framework for Multiperspective Rendering Jingyi Yu Leonard McMillan Eurographics Symposium on Rendering 2004 Multi Center of Projection Images Paul Rademacher Gary Bishop SIGGRAPH 98 Today Illumination Shading 1 million triangles drawn with 1 color per triangle 4 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 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 5 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 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 6 Lambert s Law for Diffuse Reflection Purely diffuse object n I d I L kd max cos 0 I L kd max n L 0 L I d resulting intensity diffuse I L light source intensity kd diffuse surface reflectance coefficient kd 0 1 angle between normal light direction 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 7 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 Examples of Phong Specular Model Diffuse only Diffuse Specular shininess 5 Diffuse Specular shininess 50 8 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 Our Three Basic Components of Illumination Diffuse I Id Specular I Is Ambient I I a ka 9 Combined for the Final Result I I d I s I a ka 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 10 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
View Full Document
Unlocking...