lecture 6

13
Lecture 6 Lighting

Upload: todd-riggs

Post on 30-Dec-2015

26 views

Category:

Documents


2 download

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 Presentation

TRANSCRIPT

Page 1: Lecture 6

Lecture 6

Lighting

Page 2: Lecture 6

Introduction• What is light?

• How do we percept colors?

• Lights in OpenGL

Page 3: Lecture 6

Different Types of Light• Ambient

• Diffuse

• Specular

Page 4: Lecture 6

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

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

Defining Light Source

Page 7: Lecture 6

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

Enabling Light• glEnable(GL_LIGHTING)• glEnable(Light Source)

– Eight light source (0-7)

• Specifying shade model– glShadeModel(GL_SMOOTH)

Page 9: Lecture 6

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

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

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

Next Class• Review

• Discussion for Midterm

• Troubleshooting

Page 13: Lecture 6

Questions?