Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.

Similar presentations


Presentation on theme: "Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003."— Presentation transcript:

1 Lighting Review & Example Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003

2 17 Nov 2003CS 3812 Review: The Phong Model Here is a summary of the three components of the Phong Model, along with the recommended colors to use for each type of light & reflection. Type of LightType of Reflection Ambient Light Direct Light Diffuse Reflection Specular Reflection Phong Model Ambient Component Diffuse Component Specular Component Color: Paint color Color: White?? Color: Direct light color Color: Dim version of direct light color OR black??

3 17 Nov 2003CS 3813 Review: The Phong Model [2/4] To compute the ambient component of the Phong Model, we need: The light color of the ambient light (A R, A G, A B ). The paint color of the material of the surface the vertex lies on (M R, M G, M B ). The resulting color is found via componentwise multiplication: (A R M R, A G M G, A B M B ).

4 17 Nov 2003CS 3814 The diffuse component works much like the ambient, except that it matters at what angle the light hits the surface. Do the lighting computation as for ambient. Use the direct-light color, not the ambient-light color. Multiply R, G, B the Lambert cosine k. This is the dot product of the normal and light-direction vectors, assuming these are unit vectors. If we are doing attenuation, multiply R, G, B by 1/d 2. For the specular component, both the illumination and viewing directions matter. Do the lighting computation as for ambient. Use the direct-light color, as with diffuse. And use the specular-reflection color, not the paint color. Multiply R, G, B by (R·V) s, where V is the viewing direction, and s is the shininess. If desired, do attenuation as for diffuse. Review: The Phong Model [3/4]

5 17 Nov 2003CS 3815 Review: The Phong Model [4/4] We have seen how the Phong Model computes the effects of ambient, diffuse, and specular reflection. Now, what is the color of the vertex? How about just adding these up? Final red = ambient red + diffuse red + specular red. Similarly for green & blue. But this may result in RGB components greater than 1. Solution: If any of R, G, B ends up being greater than 1, set it equal to 1. This is not entirely satisfactory, but at least it gives legal results.

6 17 Nov 2003CS 3816 Review: Basic OpenGL Lighting OpenGL implements the Phong Model. We still generally need to compute normals ourselves. We set up lights and materials; OpenGL does the rest. How it works: Set up and enable one or more lights (light sources). Use glLight *, glEnable. Various other lighting properties can be set. With glLightModel *, glShadeModel, etc. Enable/disable lighting as appropriate. Enable with “ glEnable(GL_LIGHTING); ”. When drawing, set material properties. Use glMaterial *. Forget about glColor *, for now. Before each glVertex * command, specify a normal vector. Use glNormal *.

7 17 Nov 2003CS 3817 Review: Normal Vectors When we do lighting, each polygon vertex needs an associated normal vector. This should be a unit vector pointing straight out from the surface at the vertex. In OpenGL We specify a normal with glNormal *, inside glBegin - glEnd. A glNormal* call comes before the associated glVertex *. Example: glNormal3d(0., 0., 1.); glVertex3d(1., 2., 3.); The tricky part is computing the normals. We discussed three methods. Facet normals using cross products. See the code fragment drawtriangle.cpp, on the web page. Normals based on the mathematical formula for the surface. Other methods.

8 17 Nov 2003CS 3818 Moving Lights Example: Lights and Model/View A light is something to be positioned within the world, just like a polygon. Therefore, it is natural that light positions pass through the model/view transformation. The matrix used is the current one at the time when glLightfv( …, GL_POSITION, … ) is called. Not the current one when a lit object is drawn! Therefore, you probably want to position your lights in the display function … If you want a light to move. If you want to make a light source visible by drawing an object at its location. If you have any other reason to be interested in exactly where your lights are. You can still set a light’s colors in the initialization, then set its position in the display function.

9 17 Nov 2003CS 3819 Moving Lights Example: An Object at the Light Position Suppose we want to draw an object at the light position. It should appear to be the light source. We want to position the object using model/view. If we use this same model/view matrix for setting the light position, then we will specify the light position as: (0, 0, 0, 1). We probably want the color of the object to match the color of the direct light. Make the light color a global? OpenGL material spec’s add an “emission” color to the Phong model. Its effect on the vertex color ignores light-source colors and angles. In short, it’s rather like glColor *, except that it is added to the other components in the Phong Model. Use GL_EMISSION to set the emission color.

10 17 Nov 2003CS 38110 Moving Lights Example: Example Animate the following scene: A rotating object in the center. A moving light revolving about the object. The light should be “visible”.


Download ppt "Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003."

Similar presentations


Ads by Google