lecture 6
DESCRIPTION
Lecture 6. Lighting. Introduction. What is light? How do we percept colors? Lights in OpenGL. Different Types of Light. Ambient Diffuse Specular. Defining Lights in OpenGL. Defining Light Source Defining Material Defining Light Model - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/1.jpg)
Lecture 6
Lighting
![Page 2: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/2.jpg)
Introduction• What is light?
• How do we percept colors?
• Lights in OpenGL
![Page 3: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/3.jpg)
Different Types of Light• Ambient
• Diffuse
• Specular
![Page 4: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/4.jpg)
Defining Lights in OpenGL
• Defining Light Source• Defining Material• Defining Light Model
Note: glColor will NOT work when using light in OpenGL
![Page 5: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/5.jpg)
Light Source• Light sources are:
– Directional: • Source resides in infinity• Light rays are parallel• Example: Sun.
– Positional• Source resides in local scene• It radiates all directions by default unless
restricted by defining a spot light• Example: Desk lamp
![Page 6: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/6.jpg)
Defining Light Source
![Page 7: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/7.jpg)
Adding Light Source
void glLightv(GLenum light, GLenum pname, TYPE *param);
Example:GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
![Page 8: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/8.jpg)
Enabling Light• glEnable(GL_LIGHTING)• glEnable(Light Source)
– Eight light source (0-7)
• Specifying shade model– glShadeModel(GL_SMOOTH)
![Page 9: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/9.jpg)
Be Aware of Defaults• When lighting is enabled, all the default
values for all lights are loaded as shown in the table, unless you cancel them.
• Use lights other than light0 if you want them to be cancelled by default.
• Lights [1-7] have most of their default RGB values black.
![Page 10: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/10.jpg)
Pitfall• When you use translate/rotate, it
applies to light direction and position as well.
• Solution: Use push/pop matrix if you don’t want your light sources to be affected.
![Page 11: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/11.jpg)
Light Position/DirectionGLfloat light_position[] = { x, y, x, w };
W : Defines if the light source resides in infinity or in local scene.X, y, z: Location of light if light source resides in local view Or,
Direction of light if the light source resides in infinity.
![Page 12: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/12.jpg)
Next Class• Review
• Discussion for Midterm
• Troubleshooting
![Page 13: Lecture 6](https://reader035.vdocuments.mx/reader035/viewer/2022072013/56812c61550346895d90f549/html5/thumbnails/13.jpg)
Questions?