<- previous    index    next ->

Lecture 7, Lighting in 3D

Chapter 6 of our Textbook: Interactive Computer Graphics, gives the
definitions and equations for doing lighting in any language on
any graphics platform. Programming these yourself is often a project
in CMSC 435, Computer Graphics. Many graphics toolkits implement
the lighting models for reasonably convenient use.

The physics:
  Light is electro magnetic radiation. Each color has a wavelength.
  We are interested in the visible spectrum between infrared
  and ultraviolet. From long ago, Roy G Biv, Red, orange, yellow,
  Green, Blue, indigo, violet. RGB are the electronic primary colors.
  The human eye can detect the intensity and wavelength of light.

  White light is all colors, black is no colors.
  In ambient white light, an object looks red because the object
  is reflecting light with wavelengths near red and absorbing light
  at other wavelengths

Graphics definitions:
  Ambient light: comes from no specific source, exists in all directions.
  Diffuse light: has a point source, strikes the surface of an object at
                 some angle, reflects or is absorbed by an object, the 
                 amount of reflected light depends on the incident angle
                 and the normal to the surface.
  Specular reflection: comes from point source light reflected to a pixel
                       based on the angle of incidence and angle of
                       reflection, and takes into account the shininess
                       of an object. This produces a highlight or bright spot.

  An object is said to have a surface material and that material can
  have Ambient, Diffuse and Specular properties (for each primary color).

Example programs covered: (execute and observe lighting)
planets.c
SphereMotion.java
teapots.c
teapots.jpg

The lighting environment is the physical objects in the truncated
tetrahedron plus the light(s) that may be outside this volume.
(shown in class on board, see book 5.5)



The components of light that the user sees is intensity, I, of
the primary colors RGB.
  Irgb = Iambient + Idiffuse + Ispecular   [clamped to 1.0 maximum each color]
(shown in class on board, see book 6.1-6.5)

The intensity of a pixel on the display is computed independently
for each primary color. Each intensity is the result of light on
the material of the object being reflected to the pixel on the
display screen. For the following we assume the material on the
object has been defined to provide the reflectivity of each primary
color for ambient reflection, diffuse reflection, specular reflection
and shininess. We assume that ambient light has been defined with
the amount of light for each primary color. We assume that one or more
point lights have been defined at some position with the amount of
light for each primary color. All lights and reflectivities are
assumed converted to the range 0.0 to 1.0. Any undefined value is
considered to be 0.0.

The intensity for each color is computer by the formulas:

 Iambient = Kambient * Lambient 

            Kambient is the materials reflectivity to each color
            Lambient is the amount of ambient light for each color

 Idiffuse = Kdiffuse (Lvector dot Nvector) Ldiffuse

            Kdiffuse is the materials reflectivity to each color
            Ldiffuse is the amount of one point light for each color
            Lvector is the vector from the point light to the surface
            Nvector is the normal vector at the surface
            the dot product computes the cosine of the angle between vectors

 Ispectral = Kspecular (Rvector dot Vvector)^alpha  Lspecular

            Kspecular is the materials reflectivity to each color
            Lspecular is the amount of one point light for each color
            alpha is the exponent of the dot product, typically 20 to 100
            alpha can be derived from the amount of shininess of the object
            Rvector is the reflection vector
            Vvector is the vector to the eye
            (actual computation uses a transformation, Hvector)


A few examples:
  red light amount   red reflectivity    result intensity
        0.0              0.0                 0.0
        0.0              1.0                 0.0
        1.0              0.0                 0.0
        1.0              1.0                 1.0
        0.5              0.5                 0.25

   1.00^50 = 1.0
   0.99^20 = 0.8     alpha = 20  at angle T, 0.99 = cos(T)
   0.95^20 = 0.35
   0.99^50 = 0.6     alpha = 50
   0.95^50 = 0.076

teapots  includes both lighting and texturing, which
are both closely related to how people interpret,
visualize,  the display of graphical objects.
Texturing is covered more in the next lecture.

light_dat.c
datread.c
datread.h
drop.dat Utah .dat or .det formats
skull.dat example
skull.jpg rendered as brass
bull.dat example
bull.jpg rendered as brass


There are many 3D graphical images available from the Utah project(s).
The  .det  format uses binary IEEE floating point and binary "C"
integers for fast input. The  .dat  format is exactly the same
numeric values encoded as ASCII text readable by "C" fscanf or
equivalent.

planets.c Lighted extension of planet.c
This demonstrates putting a light inside an object to give somewhat an
illusion of a glowing object.

Compare above to planet.c
 
    <- previous    index    next ->

Other links

Go to top