蔡侑庭 (Yu-Ting Tsai) Department of Computer Science National Chiao Tung University, Taiwan Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification OpenGL Programming Guide, Chap. 5
2 http://caig.cs.nctu.edu.tw/course/cg2007/files /week_5.zip void MyInit() {... } void MyDisplay() {... }
3 Vertex Streams Transformations T f ti & Vertex Operations Primitive Operations Rasterization Pixel O Operations Memory
4 P
5 P
6 r h n l v P
7 P
8 OpenGL lighting is based on modified Phong reflection model Lighting is computed at each vertex (not each face or pixel) OpenGL only considers local l illuminationi No shadows, inter-reflection, refraction, transmission,, etc. If lighting is disabled, vertex colors are adopted as lighting colors
9 Modified Phong Model
10 Initialization Enable Lighting (glenable) GL_LIGHTING, GL_LIGHT0,, GL_LIGHTn Object Drawing Set Light Parameters (gllight) Set Material Parameters (glmaterial) Set Vertex Normals (glnormal)
11 Light sources are virtual objects (invisible) Three types of light sources Point lights, directional lights, and spotlights OpenGL supports multiple light sources Each light source has its own parameters Colors, position, spotlight parameters, & attenuation coefficients
12 Set Light Colors Ambient, diffuse, & specular colors GLfloat afdiffuse[] = { 0.5, 0.6, 0.9, 1.0 }; gllightfv( GL_LIGHT0, GL_DIFFUSE, afdiffuse );
13 Set light position (with non-zero w) Set all spotlight parameters to defaults P
14 Set light position (with zero w) Light direction is implicitly set as [-x, -y, -z] Set all spotlight parameters to defaults P
15 Set light position (with non-zero w) Set spotlight direction s and cut-off angle θ Set spotlight exponent e φ s θ P
16 Intensity of light decreases as distance from the light increases No effect on directional lights
17 Three Attenuation Coefficients Constant, linear, and quadratic coefficients d i P
18 Light position and spotlight direction are in object coordinates Automatically transformed by modelview matrix Lighting colors can be computed in either object or eye coordinates Vertex positions and viewpoint should also be in the same coordinates Translations, rotations, & scaling Output colors are clamped to [0, 1]
19 Materials describe how object surface reacts to incident light OpenGL only considers local l reflection and emission Parameters of front and back faces can be set separately GL_FRONT, GL_BACK, & GL_FRONT_AND_BACK
20 Set Ambient, Diffuse, & Specular Colors Ratio of which a color channel is reflected GLfloat afdiffuse[] = { 0.9, 0.3, 0.1, 1.0 }; glmaterialfv( GL_FRONT, GL_DIFFUSE, afdiffuse );
21 Set Emissive Color How much intensity is emitted from an object GLfloat afemission[] = { 0.1, 0.1, 0.2, 1.0 }; glmaterialfv( GL_FRONT, GL_EMISSION, afemission );
22 Set Specular Exponent Control local reflectance distributions Larger more concentrated on the reflected direction more specular
23 r P
24 Change Light & Material Properties Single Light Multiple Lights
25 Texture Mapping Simple Mapping MIP-Mapping
26 Phong Shading Gouraud Phong
27 Bump Mapping Before After
28 Rules Write code for ALL listed requirements on your own Achieve all requirements by OpenGL fixed pipeline or your own code If you really prefer shaders, contact me first for additional requirements Otherwise, no shaders are allowed in this assignment
30 Local & Global Lighting Models OpenGL Light Parameters OpenGL Material Parameters Assignment II
31 OpenGL Texture Mapping OpenGL Texture Stages Recitation of Selected Topics?
32 How to implement Phong shading when OpenGL does not support per-pixel lighting? OpenGL focuses on functionality It does not care what is your input You can DRAW anything! Input OpenGL Black Box Output
33 Prof. Wen-Chieh Lin s CG Slides OpenGL Specifications http://www.opengl.org/documentation/specs/ /d t ti / / OpenGL Programming Guide, Chap. 5 Sudhansu K. Semwal s OpenGL Tutorial http://www.cs.uccs.edu/~semwal/indexgltutorial.html Nate Robin s OpenGL Tutor Program http://www.xmission.com/~nate/tutors.html i / t /t t
34 Thank You! Any Questions?