Where We StandNormal VectorsNormals and OpenGLMore Normals and OpenGLLocal Shading ModelsLocal Shading Models (Watt 6.2)“Standard” Lighting ModelDiffuse IlluminationDiffuse ExampleSpecular Reflection (Phong Model)Specular ExampleSpecular Reflection SpeedupPutting It TogetherColorApproximations for SpeedOpenGL ModelOpenGL Commands (1)OpenGL Commands (2)Shading InterpolationFlat shadingGourand ShadingPhong InterpolationPowerPoint PresentationShading and OpenGLThe Full StoryWhere We Stand•So far we know how to:–Transform between spaces–Rasterize–Decide what’s in front•Next–Deciding its intensity and colorNormal Vectors•The intensity of a surface depends on its orientation with respect to the light and the viewer–CDs are an extreme example•The surface normal vector describes the orientation of the surface at a point–Mathematically: Vector that is perpendicular to the tangent plane of the surface•What’s the problem with this definition?–Just “the normal vector” or “the normal”–Will use N to denoteNormals and OpenGL•You must supply per-vertex normal vectors if you enable lighting computations–A common oversight - all surfaces are black and may be invisible•Before specifying each vertex, specify a color and a normal vector:–glColor4f(r, g, b, a) defines a color, with many variants–glNormal3f(x, y, z) defines a normal, with many variants•Chapters 2, 4 and 5 of the OpenGL programming guide have many examplesglBegin(GL_QUADS); glColor3f(1,1,1); glNormal3f(0,0,1); glVertex3f(1,1,0); glColor3f(1,1,1); glNormal3f(0,0,1); glVertex3f(-1,1,0); glColor3f(1,1,1); glNormal3f(0,0,1); glVertex3f(-1,-1,0); glColor3f(1,1,1); glNormal3f(0,0,1); glVertex3f(1,-1,0);glEnd();More Normals and OpenGL•Specifying fewer colors and normals–OpenGL uses the notion of a current color and a current normal–The current normal is applied to all vertices up to the next normal definitionglBegin(GL_QUADS); glColor3f(1,1,1); glNormal3f(0,0,1); glVertex3f(1,1,0); glVertex3f(-1,1,0); glVertex3f(-1,-1,0); glVertex3f(1,-1,0);glEnd();•Normalizing normals–Normal vectors must be unit vectors for lighting to work correctly (they must be normalized)–By default, vectors are not normalized for you–Causes problems with scaling transformations, but OK for translations and rotations–glEnable(GL_NORMALIZE) or glEnable(GL_RESCALE_NORMAL) will fix it for you, but they are expensive and slow renderingLocal Shading Models•Local shading models provide a way to determine the intensity and color of a point on a surface–The models are local because they don’t consider other objects at all–We use them because they are fast and simple to compute–They do not require knowledge of the entire scene, only the current piece of surfaceLocal Shading Models (Watt 6.2)•What they capture:–Direct illumination from light sources–Diffuse and Specular components–(Very) Approximate effects of global lighting•What they don’t do:–Shadows–Mirrors–Refraction–Lots of other stuff …“Standard” Lighting Model•Consists of three terms linearly combined:–Diffuse component for the amount of incoming light reflected equally in all directions–Specular component for the amount of light reflected in a mirror-like fashion–Ambient term to approximate light arriving via other surfacesDiffuse Illumination•Incoming light, Ii, from direction L, is reflected equally in all directions–No dependence on viewing direction•Amount of light reflected depends on:–Angle of surface with respect to light source•Actually, determines how much light is collected by the surface, to then be reflected–Diffuse reflectance coefficient of the surface, kd•Don’t want to illuminate back side. Use )( NL -idIk)0,max( NL -idIkDiffuse ExampleWhere is the light?Specular Reflection (Phong Model)•Incoming light is reflected primarily in the mirror direction, R–Perceived intensity depends on the relationship between the viewing direction, V, and the mirror direction–Bright spot is called a specularity•Intensity controlled by:–The specular reflectance coefficient, ks–The parameter, n, controls the apparent size of the specularity•Higher n, smaller highlightnisIk )( VR -LRVSpecular ExampleSpecular Reflection Speedup•Compute based on normal vector and “halfway” vector, H–Easier to compute than mirror direction–Same resultnisIk )(2/)(NHVLH-L VNHPutting It Together•Global ambient intensity, Ia:–Gross approximation to light bouncing around of all other surfaces–Modulated by ambient reflectance ka•Just sum all the terms•If there are multiple lights, sum contributions from each light•Several variations, and approximations … nsdiaakkIIkI )()( NHNL --Color•Do everything for three colors, r, g and b•Note that some terms (the expensive ones) are constant•For reasons we will not go into, this is an approximation, but few graphics practitioners realize it–Aliasing in color space–Better results use 9 color samples–Watt discusses it in section 15.4 nrsrdrirararkkIIkI )()(,,,,,NHNL --Approximations for Speed•The viewer direction, V, and the light direction, L, depend on the surface position being considered, x•Distant light approximation:–Assume L is constant for all x–Good approximation if light is distant, such as sun•Distant viewer approximation–Assume V is constant for all x–Rarely good, but only affects specularitiesOpenGL Model•Allows emission, E: Light being emitted by surface•Allows separate light intensity for diffuse and specular•Ambient light can be associated with light sources•Allows spotlights that have intensity that depends on outgoing light direction•Allows attenuation of light intensity with distance•Can specify coefficients in multiple ways•Too many variables and commands to present in class•The OpenGL programming guide goes through it allOpenGL Commands (1)•glMaterial{if}(face, parameter, value)–Changes one of the coefficients for the front or back side of a face (or both sides)•glLight{if}(light, property, value)–Changes one of the properties of a light (intensities, positions, directions, etc)–There are 8 lights: GL_LIGHT0, GL_LIGHT1, …•glLightModel{if}(property, value)–Changes one of the global light model properties (global ambient light, for instance)•glEnable(GL_LIGHT0) enables GL_LIGHT0OpenGL Commands (2)•glColorMaterial(face, mode)–Causes a
View Full Document