130 likes | 290 Views
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
E N D
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 Note: glColor will NOT work when using light in OpenGL
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
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);
Enabling Light • glEnable(GL_LIGHTING) • glEnable(Light Source) • Eight light source (0-7) • Specifying shade model • glShadeModel(GL_SMOOTH)
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.
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.
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.
Next Class • Review • Discussion for Midterm • Troubleshooting