1 / 26

Light Sources

Light Sources. Lecture 8 SE309-Computer graphics. Outline. Light Sources The Default Model Light Source LIGHT0 Directional Light Sources Moving the Light Sources Types of Light Ambient Light Diffuse Light Specular Light Assignment. Lighting and Reflection.

carlow
Télécharger la présentation

Light Sources

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. Light Sources Lecture 8 SE309-Computer graphics

  2. Outline • Light Sources • The Default Model • Light Source LIGHT0 • Directional Light Sources • Moving the Light Sources • Types of Light • Ambient Light • Diffuse Light • Specular Light • Assignment

  3. Lighting and Reflection • The shade of a pixel is determined by two things: • The properties of 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.

  4. Types of Light Source • Definition (Ambient Light Source) • An ambient light source has no position in space. The light strikes objects equally from all directions. • Definition (Point Light Source) • A point light source is located at a point in space. The light strikes different objects from different directions depending on their position relative to the light source. • Definition (Directional Light Source) • A directional light source is located “at infinity.” The light strikes all objects from the same direction.

  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). • We will talk about that later on.

  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 amb[] = {1.0, 1.0, 1.0, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);

  7. Light Source LIGHT0 • OpenGL supports up to 8 separate light sources, each with its own characteristics. • They are named LIGHT0, LIGHT1, . . . , 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.

  8. Defaults for Light Sources • Defaults for LIGHT0. • 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). • Position (0:0; 0:0; 1:0).

  9. Enabling Lights • Each light must be enabled. • To enable LIGHT0, make the function call glEnable(GL_LIGHT0); • The other light sources are enabled in a similar way.

  10. Point vs. Directional Sources • At each point of a surface, the incident light has a direction. • With a point source, the direction varies with position of the illuminated object. • With a directional source, direction is the same for all objects. • Furthermore, with a point source, the intensity may vary with the distance from the source if we enable light attenuation.

  11. Positioning the Lights • Example (Positioning LIGHT0) floatlight_position[] = {10.0, 10.0, 10.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  12. 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 (position (0; 0; 1; 0)). • The above example gives the light the direction vector (0; 0; -1), but no position in space. • In other words, for objects in all locations, the light will shine from the direction (0; 0; -1).

  13. 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 illumination of the objects remains the same when the camera is moved. • If they are relative to the camera, then the lights move with the camera, changing the illumination of the objects.

  14. Positioning the Light Sources • To make the light source fixed (in world coordinates), the light’s position should be set after the camera is set. • Then 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. • Then the lights will not move with the scene.

  15. Positioning the Light Sources • Example (Fixed Light Sources) setView(); setLights(); • Example (Moveable Light Sources) setLights(); setView();

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

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

  18. 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 (ambient, diffuse, etc.) • The light intensity.

  19. Setting the Ambient Light • Example (Setting the Ambient Light for LIGHT0) float light_ambient[] = {0.3, 0.3, 0.3, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

  20. Diffuse Light • 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.

  21. Setting the Diffuse Light • Example (Setting the Diffuse Light for LIGHT0) float light_diffuse[] = {0.5, 0.5, 0.5, 1.0}; glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

  22. Specular Light • Intensity of reflected specular light varies with viewing direction. • Maximum intensity is in the direction pointing directly along the angle of reflection.

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

  24. 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.”

  25. Setting the Specular Light • Example (Setting the Specular Light for LIGHT0) float light_specular[] = {1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

  26. Homework • Read Chapter5 – Light sources. • Read Chapter5 – Light sources in OpenGL.

More Related