Shadows (Rob Laddish)
Shadows add additional depth cues to the scene. Shadows for the virtual cue stick
are especially important because it informs the user how far away they are from
the felt surface of the table.
Possibilities:
There are 3 different shadows present:
- Bumpers only cast shadows from their undersides. This is an easy
calculation to perform.
- Pool Balls cast elliptical shadows.
- The virtual Cue Sticks casts a complex shadow, as it consists of
many cylinders.
There are many different ways to find the shadows boundaries. The following
discussion will talk about how to model the virtual cue shadow:
- A simple, thick line can be used to draw the shadow on the felt.
The endpoints of the line would be where the ray from the light source to
either end of the cue intersects the felt. This is simple to compute, but
it will not result in larger shadows as the cue height is changed.
- A projected rectangle provides a good aproximation. To form this
rectangle, we convert the end points of the cue from cue space to table
space, then we determine the 2 points to the left and right edges of the
tip of the cue, where all of these points have the same z-value. We do
the same for the other end of the cue (and a differenty set of z-values).
We then project the ends of this rectangle down to the felt and draw it.
The width of the rectangle varies depending on which end of the cue is
higher than the other and based on the height of the cue above the table.
This looks much better, and the math simplifies into very few operations,
so it is very fast to perform. The only downside occus when the cue is
pointing straight up or straight down. In this case, if we are under a
light, the shadows may dissapear.
- A full projection of all the polygons in the cue has also been
implemented. It is slower, but it creates the correct outline. The normal
of each polygon is checked, and the projected polygons points are drawn in
reverse order if needed to preserve counter-clockwise order. This method
looks good with modified texture maps, but looks bad with alpha blending
because various polygons overlap and cause the shadow to be unaturally
chunky in places. We implemented this method as well. The methods can be
switched during run time by use of virtual button menus on the display.
There are many different ways to draw the shadow surfaces:
- Darker Felt Textures can be painted to represent shadows on the felt.
This would be very quick to draw, but multiple overlapping shadows would not
create a darker surface. This would also require a separate texture map for
every texture used that may have a shadow. This is implemented, but not
currently setup in the config file.
- Alpha Blending can be used to draw dark shadows above the surface and
then blend it with the existing surface to darken it. This is the approach that
I use. Shadows cast from multiple light sources overlap to create a darker
surface. The disadvantage with this approach is that it forces us to draw the
entire world first, then draw the shadows from each light source in
successive steps in increasing values of z. This method has problems with full
projections because the polygons overlap multiple times in odd places, which
causes a chunky shadow to be drawn.
Problems Encountered
With no shadows on, users had difficulty hitting the ball with the virtual cue.
Shadows add extra depth cues and improve the situation immensly. Users still miss
hitting balls perhaps 1 time out of 7, but this is much better than only hitting them
1 time out of 7 like before. Also, shadows are only drawn on the felt, and they are
not clipped, so they can extend into free space outside of the table.
However, the carpet is so dark, that the lack of clipping is almost unnoticable.
The shadow effect would be improved if shadows also showed up on other parts of the
table beside the felt, such as the bumpers and table edges. We modify the alpha
values in the texture map and use texture coordinates to cause the shadows to be
lighter the further away we get from the light source.
Related config file paramters:
- shadow_param opaque r,g,b mat text,text_mult,text_mat. This defines
the key components of the shadows. Opaque is ignored, rgb is the color of
the shadow, mat is the lighting material, text is the texture index, and
text_mult is used to scale texture coordinates. text_mat specifies the
material to be used if both textures and lighting are enabled.
- use_shadow value This is used to turn shadows on/off by default. The
user can still enable/disable shadows from the online button menus.
See Also: