CSCE 441 Lecture 17

From Notes
Jump to navigation Jump to search

« previous | Friday, February 21, 2014 | next »


Illumination Model

3 types of light

  • Ambient Light: uniform light caused by secondary reflections.
  • Diffuse Light: directly from light and scattered equally in all directions
  • Specular Light: highlights on shiny surfaces.

Ambient Light

where

  • is the intensity of ambient light
  • is the surface's ambient reflection coefficient.

This is really 3 equations (one for each of red, green, and blue)

Accounts for indirect illumination and the color of shadows.


Diffuse Light

Responsible for most of shading.

Assumes that light is reflected equally in all directions.

Handles both local and infinite light sources:

  • Infinite distance: doesn't change
  • Finite distacne: calculate for each point on surface.

where

  • is intensity of point light source
  • is diffuse reflection coefficient
  • is angle between normal and direction to light (assuming and are unit length.


Lambert's Law


Specular Light

Perfect, mirror-like reflection of light from surfaces

Forms highlights on shiny objects (metal, plastic)

where

  • is the intensity of point light source
  • is specular reflection coefficient
  • is angle between reflected vector and eye
  • is specular exponent

To find , we decompose into its parallel and perpendicular components with respect to .


Total Illumination

Light is additive, so we add all equations for each light source:


Attenuation

Decreasing intensity with distance from light

  • Linear:
  • Quadratic:
  • ???:
  • Gaussian:

where

  • is distance to light
  • is radius of attenuation for light


Spotlights

Light contribution occurs over a cone. of colatitude .


Implementation Considerations

Color components are constrained to

OpenGL

Specify Normals

glNormal3f(nx,ny,nz)

sets current normal; vertices inherit current normal

Create and Position Lights

float light_position[] = {0, -10, 0, 1};
float light_ambient[] = {.1, .1, .1, 1};
float light_diffuse[] = {.9, .9, .9, 1};
float light_specular[] = {1, 1, 1, 1};

glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);

Specify Material Properties

float mat_ambient[] = {1, 0, 0, 1};
float mat_diffuse[] = {1, 0, 0, 1};
float mat_specular[] = {1, 1, 1, 1};
float mat_shiny[] = {50};

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shiny);

Select Lighting Model

glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); // not infinite viewer
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);    // one- or two-sided surfaces