glapp
Class GLShadowOnPlane

java.lang.Object
  extended by glapp.GLShadowOnPlane

public class GLShadowOnPlane
extends java.lang.Object

A simple shadow technique casts a transparent shadow onto a floor surface (or other planar surface). Use the stencil buffer to prevent the shadow from "doubling up" (drawing over itself).

To make the shadow shape we create a matrix that transforms the object as if it is being viewed from the light's point of view, and projected onto the floor plane (see makeShadowMatrix()).

Multiply the modelview matrix by this "shadow matrix", then draw the object. Turn off lighting and texture to draw just the flat silhouette of the object. Turn off depth_test to insure that the shadow draws on top of the floor. (see drawShadow())

Set the alpha to 50% so the shadow appears as a dark area over the floor texture. This creates a problem though, as the "shadow" is actually an object that has been flattened out onto a plane. Where the object overlaps itself it appears darker, breaking the illusion of a shadow.

Use the stencil buffer to draw a mask of the shadow shape, then use a glSencilOp() setting to insure that the object is drawn only once into the shadow area (see drawShadow()). This eliminates the "doubled up" areas and the shadow looks convincing.


Constructor Summary
GLShadowOnPlane(float[] lightPosition, float[] plane, float[] shadowcolor, GLApp gl_application, java.lang.reflect.Method objectDrawFunction)
           
 
Method Summary
 void drawObject()
          draw the object that will be shadowed
 void drawShadow()
          Draw the shadowed object from the lights point of view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GLShadowOnPlane

public GLShadowOnPlane(float[] lightPosition,
                       float[] plane,
                       float[] shadowcolor,
                       GLApp gl_application,
                       java.lang.reflect.Method objectDrawFunction)
Method Detail

drawObject

public void drawObject()
draw the object that will be shadowed


drawShadow

public void drawShadow()
Draw the shadowed object from the lights point of view. This will create the right shape for a shadow. To draw the object as a flat shape we turn off lighting and texture, and set glColor() to gray.