Download presentation
Presentation is loading. Please wait.
1
Lighting – Light Sources
Lecture 12 Wed, Sep 19, 2007
2
Lighting and Reflection
The shade of a pixel is determined by two things: The light source(s). The material properties. The light sources determine the color and intensity of the light striking the surface. The material properties determine how that light is reflected.
3
Types of Light Source Ambient Point Source Directional Source
Light source has no position in space. Point Source Light source is at a point in space. Light strikes different objects from different directions. Directional Source Light source is “at infinity.” Light strikes all objects from same direction.
4
Types of Light Source Emissive The object itself emits light.
This is really a material property, not a light source. It does not illuminate other objects.
5
The Lighting Model To use lighting, the lighting model must be enabled: glEnable(GL_LIGHTING); When lighting is enabled, shading is determined by the lighting and material properties only; the glColor() function has no effect*. *Unless you enable GL_COLOR_MATERIAL.
6
General Ambient Light The only default lighting is the general ambient light, set to (0.2, 0.2, 0.2). This is independent of all regular light sources. The function glLightModel*() can be used to change the general ambient light. float model_ambient[] = {0.5, 0.5, 0.5, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
7
Examples In the following examples, the material properties have been set to reflect all incident light.
8
Default Lighting Model
Read Run
9
Light Source LIGHT0 OpenGL supports up to 8 separate light sources, each with its own characteristics. The are named LIGHT0, …, LIGHT7. The defaults for LIGHT0 are different from the defaults for LIGHT1 through LIGHT7. Otherwise, the 8 light sources are handled in the same way.
10
Defaults for Light Sources
Ambient (0.0, 0.0, 0.0) Diffuse (1.0, 1.0, 1.0) Specular (1.0, 1.0, 1.0) Position (0.0, 0.0, 1.0) Defaults for LIGHT1 through LIGHT7 All types of light (0.0, 0.0, 0.0)
11
Enabling Lights Each light must be enabled.
To enable LIGHT0, make the function call glEnable(GL_LIGHT0);
12
Default Settings for LIGHT0
Read Run
13
Point and Directional Sources
At each point of a surface, the light has a direction. Point source – direction varies with position on surface. Directional source – direction does not vary with position on surface. Furthermore, with a point source, the intensity may vary with the distance from the source if we enable light attenuation.
14
Positioning the Lights
Each light can be positioned at any point. OpenGL code to position LIGHT0: float light_position[] = {10.0, 10.0, 10.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, light_position);
15
Positioning Lights at Infinity
A light source may be placed “at infinity” by setting the fourth coordinate to 0.0. float light_position[] = {1.0, 1.0, 1.0, 0.0}; The default type is directional. This example gives the light the direction vector (1, 1, 1), but no position in space. In other words, for objects in all locations, the light will shine from the direction (1, 1, 1).
16
LIGHT0 Positioned at (10, 10, 10) Read Run
17
Positioning the Light Sources
The light sources may be set relative to the world coordinates (fixed) or relative to the camera (moveable). If they are relative to world coordinates, then the lighting remains the same when the camera is moved. If they are relative to the camera, then the lights move with the camera.
18
Positioning the Light Sources
To make the light source fixed, the light’s position should be set after the camera is set. When the camera moves the scene, the lights move with the scene. To make the light source move with the camera, the light’s position should be set before the camera is set. The lights will not move with the scene.
19
Positioning the Light Sources
We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); // Moveable lights setLights(); setView();
20
Positioning the Light Sources
We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); Lights are transformed with the scene // Moveable lights setLights(); setView();
21
Positioning the Light Sources
We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); // Moveable lights setLights(); setView(); Lights are not transformed with the scene
22
Fixed vs. Moveable Lights
Read Run
23
Ambient Light Ambient light illuminates objects equally in all directions. In real life, ambient light is light that has been reflected off so many surfaces that it is impossible to identify the source.
24
Ambient Reflection The ambient reflection depends on
The ambient light inherent in the scene. The ambient light given off by the light sources. The ambient property of the surface.
25
Setting the Light Properties
The function glLight*() is used to set the various light properties, such as ambient light. It takes three parameters The light source. The light property. The value.
26
Setting the Ambient Light
OpenGL code to set the ambient light for LIGHT0: float light_ambient[] = {0.3, 0.3, 0.3, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
27
LIGHT0 Ambient Light (0.3, 0.3, 0.3) Read Run
28
Diffuse Reflection Intensity of reflected diffuse light
Depends on angle of incidence. Reflects equally in all directions, i.e., does not depend on the viewing angle. It can be computed more efficiently if the light is directional, since there is one less variable.
29
Setting the Diffuse Light
OpenGL code to set the diffuse light for LIGHT0: float light_diffuse[] = {0.5, 0.5, 0.5, 1.0}; glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
30
LIGHT0 Diffuse Light (0.5, 0.5, 0.5) Read Run
31
Specular Reflection Intensity of reflected specular light varies with viewing direction. Maximum intensity is in the direction pointing directly along the angle of reflection.
32
Specular Reflection Specular reflection creates the appearance of “shininess.” Surfaces with a high specular reflection appear very shiny. Surfaces with a low specular reflection appear matte.
33
Specular Reflection Computing specular reflection is less efficient than computing diffuse reflection, since it depends on the direction to the viewer as well as the position of the light source. The calculations can be speeded up if the viewer is placed “at infinity.”
34
Setting the Specular Light
OpenGL code to set the specular light for LIGHT0: float light_specular[] = {1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.