Lighting - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Lighting

Description:

glLightfv(gl light, gl light property, values); GL_LIGHT0. GL_LIGHT1. GL_POSITION. GL_AMBIENT ... will change the Diffuse property of the material of the ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 21
Provided by: jas5106
Category:

less

Transcript and Presenter's Notes

Title: Lighting


1
Lighting
  • Jason Goffeney
  • 4/5/2006

2
Lighting
  • Lighting along with perspective viewing adds to
    the illusion of viewing 3D on a 2D screen

3
Lighting
  • There are really 2 parts to any lighting system
  • How the lights are defined
  • How are the components of light set up?
  • How many lights?
  • Which type of lights?
  • How objects in the scene are defined
  • How are normals set up?
  • What are the material properties?

4
Lighting
  • By default with GL lighting turned off there is
    still white ambient light. But if GL lighting
    is enabled without a light set then there is no
    lighting at all.

5
Enabling Lighting
  • To enable the lighting system
  • glEnable(GL_LIGHTING)
  • To turn on a single light
  • glEnable(GL_LIGHT0)

6
Enabling Lighting
  • The first default light has the following
    properties
  • It has no ambient component
  • It has white diffuse and specular components
  • It is located at (0, 0, 1) on the coordinate
    system

7
Components of Light
  • Ambient light is considered sourceless and
    effects everything in the scene equally.
  • It does not add any depth to a scene.

8
Components of Light
  • Diffuse light emanates from a source and has a
    direction.
  • The part of an object hit directly will be more
    brightly lit than parts where the light glances
    off.

9
Components of Light
  • Specular light is very directed light that
    reflects back to the viewer.
  • It results in the highlight seen on shiny objects
    like metal or plastics.
  • Specular light works with the material properties
    of an object. If the object is not shiny then
    specular does nothing.

10
Setting the Light Components
  • The basic function for setting lighting
    components is
  • glLightfv(gl light, gl light property, values)

Such as, light_position where light_position
0.0, 0.0, -200.0
GL_LIGHT0 GL_LIGHT1
GL_POSITION GL_AMBIENT GL_DIFFUSE
11
Setting the Light Components
  • Setting the position of the light.
  • Declare an array holding the x, y, z position of
    light
  • GLfloat light_position 0.0, 0.0, -200.0
  • Set the glLight function.
  • glLightfv(GL_LIGHT0, GL_POSITION, light_position)

12
Setting the Light Components
  • Setting the light color components.
  • Declare the arrays holding the r, g, b, w color
    components.
  • GLfloat light_ambient 0.1, 0.1, 0.1, 1.0
  • GLfloat light_diffuse 1.0, 1.0, 0.0,
    1.0
  • GLfloat light_specular 1.0, 1.0, 1.0, 1.0
  • Set the glLight function.
  • glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
  • glLightfv(GL_LIGHT0, GL_SEPCULAR,
    light_specular)

13
Setting the Light Components
  • Be sure to enable the lights when you are
    finished!
  • Other controllable properties
  • Light Attenuation
  • Spotlight Properties
  • Light Direction

14
Setting the Light Components
  • A light is basically another object in the scene
    and can be affected by transformations.
  • To keep a light in one place, set its position in
    glInitialize and forget about it.
  • To move the light set its position after some
    transformation within glPaint.

15
Defining Materials
  • Material properties are the other half of the
    model.
  • The light components interact with the material
    properties for the final result.
  • Light and material colors combine
  • Material properties create dull or shiny objects

16
Defining Materials
  • Materials can be defined once during
    initialization to affect all scene objects or
    before an object is drawn to affect it and
    anything after it until another call is made.

17
Defining Materials
  • The function
  • glMaterialfv( object face, material property,
    values)

Which side of the object faces should be included
in the model calculations GL_FRONT GL_BACK GL_FRO
NT_AND_BACK
GL_AMBIENT GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SP
ECULAR GL_SHININESS GL_EMISSION
18
Material Properties
  • Several of the properties complement their
    lighting counterparts. The others
  • GL_SHININESS A single float value used with the
    specular component to determine how tight the
    highlight it. The higher the value the smaller
    the spot.
  • GL_EMMISION Allows the material to appear as if
    it is internally lit (kind of).

19
Setting Material Properties
  • Setting the values
  • GLfloat mat_specular 1.0, 1.0, 1.0, 1.0
  • GLfloat mat_diffuse 0.0, 0.3, 0.3, 1.0
  • GLfloat mat_shininess 10.0
  • GLfloat mat_emissive 0.5, 0.5, 0.0, 1.0
  • Calling the functions
  • glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse)
  • glMaterialfv(GL_FRONT, GL_SPECULAR,
    mat_specular)
  • glMaterialfv(GL_FRONT, GL_EMISSION,
    mat_emissive)
  • glMaterialfv(GL_FRONT, GL_SHININESS,
    mat_shininess)

20
glColorMaterial
  • Once you have set your materials you may wish to
    change one for your objects using glColor.
  • Set the property to change for glColorMaterial
    within your initialization
  • glColorMaterial(GL_FRONT, GL_DIFFUSE)
  • glEnable(GL_COLOR_MATERIAL)
  • Now every call to glColor will change the Diffuse
    property of the material of the next object
Write a Comment
User Comments (0)
About PowerShow.com