Unformatted text preview:

Polygon RenderingFlat RenderingDiffuse Illumination & Flat RenderingGouraud RenderingDiffuse & Gouraud ShadingSpecular & Gouraud ShadingPhong RenderingSlide 8Specular & Phong RenderingGouraud vs. PhongDiscussionOpenGL Support for IlluminationOpenGL LightsSlide 14glLight*()SpotlightSlide 17Object MaterialsglMaterial*()Slide 20glColorMaterial()OpenGL ShadingPhong Shading with Specular IlluminationPhong Shading + Specular Illum. on Curved SurfacesMore and Better LightsImage TexturesDisplacement Textures + ShadowsPolygon RenderingFlat RenderingGoraud RenderingUses Phong ReflectancePhong RenderingFlat RenderingOne normal per triangleConstant color per triangleComputed using reflectance model.Best for flat surfaces to give a faceted appearanceAdvantages: simple and fastDiffuse Illumination & Flat Rendering Image courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see Prof. Varshney’s slides).Gouraud RenderingOne normal per vertexCompute color per vertexInterpolate color per pixel (one add per R, G, B channel)Tolerable results for curved surfacesDiffuse & Gouraud Shading Image courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see Prof. Varshney’s slides).Specular & Gouraud ShadingImage courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see Prof. Varshney’s slides).Phong RenderingOne normal per vertexInterpolate normal per pixelInterpolate each component of normal and then normalizeCompute color per pixelGood for curved and shiny surfacesNot available in OpenGLHow do we interpolate a surface normal? Keep in mind that a normal is a unit vector. We can’t just interpolate the x,y,z components of the normal, because we wind up with a non-unit normal. Here’s a simple example:N1 = (0, .436, -.9). N2 = (0, -.436,.9)If we take the average of these, we get (0,0,.9), which is not a unit normal. We have to normalize this to get (0,0,1).Specular & Phong RenderingImage courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see Prof. Varshney’s slides).Gouraud vs. PhongGouraud is fasterInterpolate 1 value instead of 3Don’t need to normalizeDon’t need to render at each point.Phong much more accurateEspecially when lighting effects change rapidly with surface normal.True for shiny objectsAnd for cast shadows.DiscussionLight Source and/or Viewer at infinity simplifies calculations at the cost of realismNeed to either clamp colors at max value or normalize them preserving their relative weights (R = R/(R + G + B) , .... )OpenGL Support for IlluminationAmbient, Diffuse, Specular illuminations are supportedUsers have to define lightsposition, type, color Users also define object materialFront and/or back facing polygons, colorOpenGL Lights GLfloat lightA_position[ ] = {1.0, 1.0, 1.0, 0.0};GLfloat lightB_position[ ] = {1.0, 2.0, 3.0, 1.0};glLightfv(GL_LIGHT0, GL_POSITION, lightA_position); glLightfv(GL_LIGHT1, GL_POSITION, lightB_position); The above defines a directional light source coming from the direction (1, 1, 1), and a positional light source located at the point (1, 2, 3) in the world coordinates.OpenGL LightsOpenGL specifies at least 8 light sources GL_LIGHT0 .. GL_LIGHT7To get maximum lights in your implementations use: glGetIntegerv(GL_MAX_LIGHTS, GLint *num_lights);You need to enable each light that you plan to use and enable OpenGL lighting (they are all disabled by default): glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); … glEnable(GL_LIGHTING);glLight*() glLight{if}(GLenum light, GLenum pname, TYPE param) glLight{if}v(GLenum light, GLenum pname, TYPE *param)light can be GL_LIGHT0 .. GL_LIGHT7pname can be one of following:GL_POSITION: light positionGL_AMBIENT, GL_DIFFUSE, GL_SPECULAR : light colorsGL_SPOT_DIRECTION, GL_SPOT_EXPONENT, GL_SPOT_CUTOFF: spotlight parametersGL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION: parameters for attenuationSpotlightDirectionCutoffglLight*() GLfloat light0_ambient[ ] = {0.0, 0.1, 0.0, 1.0};GLfloat light0_diffuse[ ] = {0.0, 0.0, 1.0, 1.0};GLfloat light0_specular[ ] = {1.0, 1.0, 1.0, 1.0};GLfloat light0_position[ ] = {1.0, 2.0, 3.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING);Object MaterialsObject colors under illumination are computed as a component-wise multiplication of the light colors and material colorsJust as light colors are specified differently for ambient, diffuse, and specular illuminations, material colors are also specified for each of these three illuminations. In addition to this emissive material color is also defined:Lights don’t influence emissive materialEmissive objects don’t add further light to environmentglMaterial*() glMaterial{if}(GLenum face, GLenum pname, TYPE param) glMaterial{if}v(GLenum face, GLenum pname, TYPE *param)face can be: GL_FRONT, GL_BACK, GL_FRONT_AND_BACKpname can be:GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION: material colorsGL_SHININESS: Specular (Phong) illumination exponentglMaterial*() GLfloat mat0_ambient[ ] = {0.2, 0.2, 0.2, 1.0};GLfloat mat0_diffuse[ ] = {0.7, 0.0, 0.0, 1.0};GLfloat mat0_specular[ ] = {1.0, 1.0, 1.0, 1.0};GLfloat mat0_shininess[ ] = {5.0}; glMaterialfv(GL_FRONT, GL_AMBIENT, mat0_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat0_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat0_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat0_shininess);glColorMaterial()If only one material property is to be changed, it is more efficient to use glColorMaterial( ) glColorMaterial( ) causes material to track glColor*( ) glEnable(GL_COLOR_MATERIAL);glColorMaterial(GL_FRONT, GL_DIFFUSE);glColor3f(0.2, 0.5, 0.8); // this changes the diffuse material color Draw objects hereglColorMaterial(GL_FRONT, GL_SPECULAR);glColor3f(0.9, 0.0, 0.2); // this changes the specular material color Draw objects hereglDisable(GL_COLOR_MATERIAL);OpenGL ShadingOpenGL supports flat and Gouraud shading. No support for Phong shading yet. glShadeModel(GL_FLAT)Flat shading glShadeModel(GL_SMOOTH)Gouraud shadingRemember to supply normals with triangles or vertices to get correct lighting and shadingPhong Shading with Specular Illumination Image courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see Prof. Varshney’s slides).Phong Shading + Specular Illum. on Curved SurfacesImage courtesy, Foley, van Dam, Feiner, Hughes(Image removed, see


View Full Document

UMD CMSC 427 - Polygon Rendering

Download Polygon Rendering
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Polygon Rendering and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Polygon Rendering 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?