Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.

Similar presentations


Presentation on theme: "CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003."— Presentation transcript:

1 CS 481 Preview, Some Lighting Details Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003

2 19 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 19 Nov 2003CS 3813 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 *.

4 19 Nov 2003CS 3814 Review: Moving Lights Example 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! Idea: For positional lights (not directional lights), always call the above with (0, 0, 0, 1) as the position. Then you can make a “visible light source” by drawing an object centered at (0, 0, 0) at the same time.

5 19 Nov 2003CS 3815 CS 481 Preview [1/2] The second semester of CG is CS 481/681, which will be taught next semester. *Class procedures will be much the same as in CS 381, except: The last few assignments will be replaced by a project. Requirements will be negotiated individually. There will be one take-home midterm exam instead of two in-class exams. A number of class meetings will be outside the classroom. For example, in the ARSC Discovery Lab.

6 19 Nov 2003CS 3816 CS 481 Preview [2/2] *CS 481/681 topics include: Virtual Reality We have received permission from ARSC for students in the class to get access (door cards & computer accounts) to the Discovery Lab. Specifying 3-D Objects Including making models for a 3-D printer. Students will each be able to “print” (at least) one 3-D model. Advanced Lighting Techniques Bump mapping, environment mapping, BRDF’s, ray tracing, etc. A Little on Shader Languages The latest advance in graphics processor control methods allow programmers to write code in a high-level language to be run by the graphics processor. And any other CG topic you might want to do a project on … *This assumes I will be the instructor, which is very likely, but not certain.

7 19 Nov 2003CS 3817 Some Lighting Details: Overview Now we look at some of the more advanced (and/or obscure) lighting features available in OpenGL: Two-sided lighting. Spotlights. Local-viewer mode.

8 19 Nov 2003CS 3818 Some Lighting Details: Two-Sided Lighting [1/2] OpenGL’s two-sided lighting mode allows the front and back of a polygon to be lit differently. When you use glMaterial *, you specify front or back or both. Thus, there are two current materials: front and back. Normally, you use only the front material. When two-sided lighting is enabled, the front material is used for the front side, and the back material for the back side.

9 19 Nov 2003CS 3819 Some Lighting Details: Two-Sided Lighting [2/2] Enable two-sided lighting with glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); Make that a zero to disable it. You probably want to put this in the initialization; there is rarely any reason to disable it. No, I don’t know why they didn’t just use glEnable. When two-sided lighting is enabled: The front side (determined by clockwise/counterclockwise vertex ordering) of a polygon is lit as usual. The front material is used. The back side is lit using: The back material. A reversed normal vector. Your normals had better point the correct direction! Example Time

10 19 Nov 2003CS 38110 Some Lighting Details: Spotlights A “spotlight” is a light source that sends light only in, or close to, a particular direction. Spotlights should always be positional, having a position in 3-D space. Three lighting parameters, all set using glLight *, affect spotlights. Spot Direction Use GL_SPOT_DIRECTION with glLightfv. Parameter is an array of 3 GLfloat ’s: a vector indicating which way the spotlight is pointing. Spot Cutoff Use GL_SPOT_CUTOFF with glLightf. Parameter is a single GLfloat : an angle, in degrees, indicating how far from the spot direction the spotlight works. Legal values: 0-90, 180. Spot Exponent Use GL_SPOT_EXPONENT with glLightf. Parameter is a single GLfloat : an exponent for the cosine of the angle between the direction to a given vertex and the spot direction.. Legal values: 0-128 (just like shininess). Hint: Exponents generally work better than cutoffs. (Why?)

11 19 Nov 2003CS 38111 Some Lighting Details: Local-Viewer Mode The specular component of the Phong Model takes the viewing direction into account. In OpenGL, by default, this is speeded up by replacing the viewer direction with (0, 0, 1). Force OpenGL to do the “correct” Phong Model computation by setting local-viewer mode. Enable local-viewer mode with glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); Other comments on enabling & disabling as for two-sided. I have generally found: The default (no local viewer) works fine for nearly all applications. Local-viewer mode might be helpful when flying. Local-viewer mode is necessary in virtual reality.


Download ppt "CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003."

Similar presentations


Ads by Google