Visualization, Spring'98, Yap

[PREVIOUS LECTURE] [NEXT LECTURE] [ALL LECTURES] [CLASS PAGE]

LECTURE 7: LIGHT

FURTHER REFERENCE: [Angel 6.7, 6.8]
INTRODUCTION
-- The proper use of light can greatly improve the visualization of 3-dimensional objects.
-- The physical properties of light is remarkably complex to model.
-- The light model adopted by OpenGL is simple and practical!
-- For instance, there are no shadows in the OpenGL light world.
OpenGL light has 3 independent color components (RGB)
LIGHT IS NOT SEEN UNTIL IT INTERACTS WITH MATERIAL!
-- How light interacts with material depends on what we call the transmission properties of light (this is not an OpenGL terminology).
OpenGL light has 3 components of tranmission properties:
  1. ambient light property -- this is general background light, with no direction.
    -- It also bounces off a surface equally in all directions.
    -- E.g.: light under the open sky in the day without the sun.
  2. diffuse light property -- this is directional light.
    -- It bounces off a surface equally in all direction,
    -- But the intensity of the reflected light is proportional to the cosine of the incidence angle (i.e., angle between the light direction and the surface normal).
    -- E.g.: daylight coming through the window in a dark room
  3. specular light property -- this is directional light
    -- It bounces off a surface with intensity that has a preferred direction
    -- The preferred direction is normally the direction of reflection of the incoming direction
    -- E.g.: light from a bright light source.
The 3 transmission components, combined with the 3 color components, imply that OpenGL light is a 9-COMPONENT ENTITY!
The interaction between light and material depends also on the material.
-- E.G. A red surface will reflect all the incoming red light and absorb all the incoming green and blue lights. If the incoming light is white, the surface will appear red. If the incoming light has no red component, the surface appears black.
-- In OpenGL, this discussion can be independently applied to each of the physical components of light.
-- Thus, the light properties of a material is includes at least the 9-components (ambient, diffuse and specular, for each of the color components).
-- But in addition, you can specify a mateiral to be emissive (a self-luminous source)
-- You can specify the material for the two sides of polygon independently.
How do the components of light and material interact?
-- roughly: the i-th (i=1,2,...,9 component of the incoming light will essentially be multiplied by the corresponding i-th component of the material.
-- These will be further attenuated by the nature of the particular component (e.g., multiplied by \cosine \theta for diffuse light).
-- Next, all these 9 components are added together in groups of threes, to form the R, G and B components for a pixel. If the final value is greater than 1, we clamp it to 1.
-- E.g., the red ambient, red diffuse and red specular values are added to form the red component.
LIGHT SOURCES:
-- You can specify several (at least 8) independent light sources.
-- Each light source has several parameters, including the 9-components of light, position and direction.
void glLight*( GLenum light, GLenum pname, TYPE param)
E.g., Ambient Light (RGBA) Properties of 0th Light:
      GLfloat ambient_0[] = {0.2, 0.2, 0.2, 1.0};
      glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_0);
E.g., Specular Light (RGBA) Properties of 3rd Light:
      GLfloat specular_3[] = {0.2, 0.2, 0.2, 1.0};
      glLightfv(GL_LIGHT3, GL_SPECULAR, specular_3);
E.g., Position of 2nd Light source is at infinity:
      GLfloat pos_2[] = {0.0, 25., 0.0, 0.0};
      glLightfv(GL_LIGHT2, GL_POSITION, pos_2);
E.g., Direction of second light source:
      GLfloat dir_2[] = {1.0, 1.0, 3.0, 0.0};
      glLightfv(GL_LIGHT2, GL_DIRECTION, dir_2);
Defaults: GL_AMBIENT is (0,0,0,1), GL_DIFFUSE and GL_SPECULAR is (1,1,1,1).
-- You can also specify a global ambient light, independent of any light source.
SPECIFYING LIGHT PROPERTIES OF MATERIAL:
-- The material properties are chosen before you define your faces:
void glMaterial*( GLenum face. GLenum pname. TYPE param)
E.g., The ambient property for the front and back faces of polygons:
      GLfloat ambient[] = {1.0, 1.0, 3.0, 0.0};
      glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
      glBegin(GL_POLYGON);
      ...etc...
      glEnd();

-- For specular light, you can specify a value (exponent) for shininess.
OTHER FACTORS:
-- Vertex normal is used in diffuse and specular light calculations
-- Be sure to enable general lighting as well as individual light sources:
glEnable( GL_LIGHTING);
glEnable( GL_LIGHT0);
SUMMARY: STEPS IN LIGHTING
  1. Create light sources
  2. Specify a light model (the 9-components of light, etc)
  3. Select normals for vertices
  4. Define properties of material
  5. Enable lighting
  6. display your objects

[PREVIOUS LECTURE] [NEXT LECTURE] [ALL LECTURES] [CLASS PAGE]