Lighting Review - PowerPoint PPT Presentation

About This Presentation
Title:

Lighting Review

Description:

Here is a summary of the three components of the Phong Model, along with the ... R, G, B by (R V)s, where V is the viewing direction, and s is the shininess. ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 11
Provided by: glenngc
Learn more at: https://www.cs.uaf.edu
Category:

less

Transcript and Presenter's Notes

Title: Lighting Review


1
Lighting Review Example
  • Glenn G. ChappellCHAPPELLG_at_member.ams.org
  • U. of Alaska Fairbanks
  • CS 381 Lecture Notes
  • Monday, November 17, 2003

2
ReviewThe Phong Model
  • Here is a summary of the three components of the
    Phong Model, along with the recommended colors to
    use for each type of light reflection.

Type of Light
Type of Reflection
Phong Model
Ambient Light
Diffuse Reflection
Ambient Component
ColorPaint color
ColorDim version of direct light colorOR
black??
Diffuse Component
Direct Light
Specular Reflection
Specular Component
ColorWhite??
ColorDirect light color
3
ReviewThe Phong Model 2/4
  • To compute the ambient component of the Phong
    Model, we need
  • The light color of the ambient light (AR, AG,
    AB).
  • The paint color of the material of the surface
    the vertex lies on (MR, MG, MB).
  • The resulting color is found via componentwise
    multiplication(ARMR, AGMG, ABMB).

4
ReviewThe Phong Model 3/4
  • The diffuse component works much like the
    ambient, except that it matters at what angle the
    light hits the surface.
  • Do the lighting computation as for ambient.
  • Use the direct-light color, not the ambient-light
    color.
  • Multiply R, G, B the Lambert cosine k.
  • This is the dot product of the normal and
    light-direction vectors, assuming these are unit
    vectors.
  • If we are doing attenuation, multiply R, G, B by
    1/d2.
  • For the specular component, both the illumination
    and viewing directions matter.
  • Do the lighting computation as for ambient.
  • Use the direct-light color, as with diffuse.
  • And use the specular-reflection color, not the
    paint color.
  • Multiply R, G, B by (RV)s, where V is the
    viewing direction, and s is the shininess.
  • If desired, do attenuation as for diffuse.

5
ReviewThe Phong Model 4/4
  • We have seen how the Phong Model computes the
    effects of ambient, diffuse, and specular
    reflection.
  • Now, what is the color of the vertex?
  • How about just adding these up?
  • Final red ambient red diffuse red specular
    red.
  • Similarly for green blue.
  • But this may result in RGB components greater
    than 1.
  • Solution If any of R, G, B ends up being greater
    than 1, set it equal to 1.
  • This is not entirely satisfactory, but at least
    it gives legal results.

6
ReviewBasic OpenGL Lighting
  • OpenGL implements the Phong Model.
  • We still generally need to compute normals
    ourselves.
  • We set up lights and materials OpenGL does the
    rest.
  • How it works
  • Set up and enable one or more lights (light
    sources).
  • Use glLight, glEnable.
  • Various other lighting properties can be set.
  • With glLightModel, glShadeModel, etc.
  • Enable/disable lighting as appropriate.
  • Enable with glEnable(GL_LIGHTING).
  • When drawing, set material properties.
  • Use glMaterial.
  • Forget about glColor, for now.
  • Before each glVertex command, specify a normal
    vector.
  • Use glNormal.

7
ReviewNormal Vectors
  • When we do lighting, each polygon vertex needs an
    associated normal vector.
  • This should be a unit vector pointing straight
    out from the surface at the vertex.
  • In OpenGL
  • We specify a normal with glNormal, inside
    glBegin-glEnd.
  • A glNormal call comes before the associated
    glVertex.
  • ExampleglNormal3d(0., 0., 1.)glVertex3d(1.,
    2., 3.)
  • The tricky part is computing the normals. We
    discussed three methods.
  • Facet normals using cross products.
  • See the code fragment drawtriangle.cpp, on the
    web page.
  • Normals based on the mathematical formula for the
    surface.
  • Other methods.

8
Moving Lights ExampleLights and Model/View
  • A light is something to be positioned within the
    world, just like a polygon.
  • Therefore, it is natural that light positions
    pass through the model/view transformation.
  • The matrix used is the current one at the time
    when glLightfv(, GL_POSITION, ) is called.
  • Not the current one when a lit object is drawn!
  • Therefore, you probably want to position your
    lights in the display function
  • If you want a light to move.
  • If you want to make a light source visible by
    drawing an object at its location.
  • If you have any other reason to be interested in
    exactly where your lights are.
  • You can still set a lights colors in the
    initialization, then set its position in the
    display function.

9
Moving Lights ExampleAn Object at the Light
Position
  • Suppose we want to draw an object at the light
    position.
  • It should appear to be the light source.
  • We want to position the object using model/view.
  • If we use this same model/view matrix for setting
    the light position, then we will specify the
    light position as
  • (0, 0, 0, 1).
  • We probably want the color of the object to match
    the color of the direct light.
  • Make the light color a global?
  • OpenGL material specs add an emission color to
    the Phong model.
  • Its effect on the vertex color ignores
    light-source colors and angles.
  • In short, its rather like glColor, except that
    it is added to the other components in the Phong
    Model.
  • Use GL_EMISSION to set the emission color.

10
Moving Lights ExampleExample
  • Animate the following scene
  • A rotating object in the center.
  • A moving light revolving about the object.
  • The light should be visible.
Write a Comment
User Comments (0)
About PowerShow.com