Скачать презентацию CS 481 Preview Some Lighting Details Glenn G Скачать презентацию CS 481 Preview Some Lighting Details Glenn G

ca43ec1558f192e3ddb6a711ccac85ca.ppt

  • Количество слайдов: 11

CS 481 Preview, Some Lighting Details Glenn G. Chappell CHAPPELLG@member. ams. org U. of 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 19 Nov 2003 CS 381

Review: The Phong Model n Here is a summary of the three components of Review: The Phong Model n 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 Light Ambient Light Color: Dim version of direct light color OR black? ? Direct Light Phong Model Ambient Component Diffuse Reflection Color: Paint color Diffuse Component Specular Component Color: Direct light color 19 Nov 2003 Type of Reflection Specular Reflection Color: White? ? CS 381 2

Review: Basic Open. GL Lighting n Open. GL implements the Phong Model. n n Review: Basic Open. GL Lighting n Open. GL implements the Phong Model. n n n We still generally need to compute normals ourselves. We set up lights and materials; Open. GL does the rest. How it works: n Set up and enable one or more lights (light sources). • Use gl. Light*, gl. Enable. n Various other lighting properties can be set. • With gl. Light. Model*, gl. Shade. Model, etc. n Enable/disable lighting as appropriate. • Enable with “gl. Enable(GL_LIGHTING); ”. n When drawing, set material properties. • Use gl. Material*. • Forget about gl. Color*, for now. n Before each gl. Vertex* command, specify a normal vector. • Use gl. Normal*. 19 Nov 2003 CS 381 3

Review: Moving Lights Example n A light is something to be positioned within the Review: Moving Lights Example n A light is something to be positioned within the world, just like a polygon. n n Therefore, it is natural that light positions pass through the model/view transformation. The matrix used is the current one at the time when gl. Lightfv(…, GL_POSITION, …) is called. • Not the current one when a lit object is drawn! n 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. 19 Nov 2003 CS 381 4

CS 481 Preview [1/2] n n The second semester of CG is CS 481/681, CS 481 Preview [1/2] n n 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: n The last few assignments will be replaced by a project. • Requirements will be negotiated individually. n n 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. 19 Nov 2003 CS 381 5

CS 481 Preview [2/2] n *CS 481/681 topics include: n Virtual Reality • We CS 481 Preview [2/2] n *CS 481/681 topics include: n Virtual Reality • We have received permission from ARSC for students in the class to get access (door cards & computer accounts) to the Discovery Lab. n 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. n Advanced Lighting Techniques • Bump mapping, environment mapping, BRDF’s, ray tracing, etc. n 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. n 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. 19 Nov 2003 CS 381 6

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

Some Lighting Details: Two-Sided Lighting [1/2] n Open. GL’s two-sided lighting mode allows the Some Lighting Details: Two-Sided Lighting [1/2] n Open. GL’s two-sided lighting mode allows the front and back of a polygon to be lit differently. n n When you use gl. Material*, 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. 19 Nov 2003 CS 381 8

Some Lighting Details: Two-Sided Lighting [2/2] n Enable two-sided lighting with gl. Light. Modeli(GL_LIGHT_MODEL_TWO_SIDE, Some Lighting Details: Two-Sided Lighting [2/2] n Enable two-sided lighting with gl. Light. Modeli(GL_LIGHT_MODEL_TWO_SIDE, 1); n n 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 gl. Enable. When two-sided lighting is enabled: n The front side (determined by clockwise/counterclockwise vertex ordering) of a polygon is lit as usual. • The front material is used. n The back side is lit using: • The back material. • A reversed normal vector. n n Your normals had better point the correct direction! Example Time 19 Nov 2003 CS 381 9

Some Lighting Details: Spotlights n A “spotlight” is a light source that sends light Some Lighting Details: Spotlights n A “spotlight” is a light source that sends light only in, or close to, a particular direction. n n Spotlights should always be positional, having a position in 3 -D space. Three lighting parameters, all set using gl. Light*, affect spotlights. n Spot Direction • Use GL_SPOT_DIRECTION with gl. Lightfv. • Parameter is an array of 3 GLfloat’s: a vector indicating which way the spotlight is pointing. n Spot Cutoff • Use GL_SPOT_CUTOFF with gl. Lightf. • Parameter is a single GLfloat: an angle, in degrees, indicating how far from the spot direction the spotlight works. • Legal values: 0 -90, 180. n Spot Exponent • Use GL_SPOT_EXPONENT with gl. Lightf. • 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). n Hint: Exponents generally work better than cutoffs. (Why? ) 19 Nov 2003 CS 381 10

Some Lighting Details: Local-Viewer Mode n n The specular component of the Phong Model Some Lighting Details: Local-Viewer Mode n n The specular component of the Phong Model takes the viewing direction into account. In Open. GL, by default, this is speeded up by replacing the viewer direction with (0, 0, 1). n n Enable local-viewer mode with gl. Light. Modeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); n n Force Open. GL to do the “correct” Phong Model computation by setting local-viewer mode. Other comments on enabling & disabling as for two-sided. I have generally found: n n n 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. 19 Nov 2003 CS 381 11