1 / 13

Lecture 6

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

todd-riggs
Télécharger la présentation

Lecture 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 6 Lighting

  2. Introduction • What is light? • How do we percept colors? • Lights in OpenGL

  3. Different Types of Light • Ambient • Diffuse • Specular

  4. Defining Lights in OpenGL • Defining Light Source • Defining Material • Defining Light Model Note: glColor will NOT work when using light in OpenGL

  5. 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

  6. Defining Light Source

  7. 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);

  8. Enabling Light • glEnable(GL_LIGHTING) • glEnable(Light Source) • Eight light source (0-7) • Specifying shade model • glShadeModel(GL_SMOOTH)

  9. 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.

  10. 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.

  11. Light Position/Direction GLfloat 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.

  12. Next Class • Review • Discussion for Midterm • Troubleshooting

  13. Questions?

More Related