Lighting
  • The final color of a pixel in the framebuffer depends partly on the lighting conditions 
  • Lighting can have a major effect on perceived shape of objects

  •  

     
     
     
     
     
     
     
     
     


     

  •  Topics:
    • Hidden surface removal
    • Controlling lighting in the scene
    • Setting illimination parameters
    • Lighting mathematics

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Hidden Surface Removal
  • Three-dimensional applications generally follow the same structure:

  •  

     
     
     
     
     
     
     
     
     

    while (1) { 
      get_viewing_point_from_mouse_position(); 
      glClear(GL_COLOR_BUFFER_BIT); 
      draw_3d_object_A(); 
      draw_3d_object_B(); 
      draw_3d_object_C(); 
    }


     

  • Hidden surface removal is accomplished with a depth buffer
  • Enable depth buffering with glEnable(GL_DEPTH_TEST)
  • Clearing the depth buffer is done with:
    • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • Hidden line removal is a a little different ...

  •  

     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Real-world and OpenGL Lighting
  • The reflected light which is perceived is a combination of multiple light sources 
  • The surface properties also have a significant effect on the object color 
  •  OpenGL simulates the lighting conditions with equasions that:
    • Approximate reality
    • Are easy to implement
  • Software renderers can calculate more realistic calculations


  • Image from http://radsite.lbl.gov/radiance/gallery/image/63b7.jpg
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  OpenGL Lighting
  • OpenGL lighting comes from a series of light sources which can be turned on or off.
  • In the real world light bounces off surfaces to contribute to the overall illumination 
    • No way to determine source
  • This is simulated in OpenGL by specifying an ambient light
  •  Each surface in the scene has a material definition
    • Specifies reflectivity
  • Some materials can emit light (emmisive)
  • OpenGL lighting model has four parameters:
    • emmisive
    • ambient
    • diffuse
    • specular
  • All four components are computed indepenently and summed

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Ambient, Diffuse, and Specular Light
 
 

Ambient illumination is light that's been scattered so much by the environment that its direction is impossible to determine: it seems to come from all directions.(spotlight)
Image from http://www.steelcase.com/products/subcategory.html

  • When ambient light strikes a surface it scatters in all directions

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Diffuse Lighting
 
  • Diffuse light comes from a single direction
    • Brighter if it strikes a surface directly
    • Scatters equally

     
     
     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Specular Light Component
  • Specular light is also directional, but scatters in a preferred direction
  • "Shiny materials" have a high specularity
  • Matte materials have low specularity

  •  

     
     
     
     
     
     
     
     
     

  • The specular, ambient and diffuse components can have different component values (white light in red room - red diffuse component)

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Material Color
  • OpenGL implements object material by specifying the color which an object reflects
  • Light and material specification determine the color of an object


  • Lighthouse image from  http://www.midwinter.com/~piaw/gallery/pigeonpointlighthouse.htm
     

  •  Light also have a diffuse, specular, and ambient color

  •  

     
     
     
     
     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Material Color (cont)
  • Diffuse and ambient terms should typically be similiar
  • Specular highlights generally match the light source 
  •  Emmissive component adds intensity to the object, but not the overall lighting of the scene.
    • Simulates a self-illuminating object

     
     
     
     
     
     

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 


 

  RGB Values for Lights and Materials
  • RGB values are different between Lights & Materials:
    • Lights: Intensitity
    • Materials: Reflectivity
  •  For a given light (LR, LG,LB) light reaching the eye is:
    • (LR * MR, LG * MG, LB * MB) (ignoring other reflectivity factors)
  • Multiple lights are accumulated, and clamped to 1.0 

  •