On Wednesday 12 May 2004 20:04, Andy Ross wrote:
> Lee Elliott wrote:
> > Was the stencil shadow stuff for generating object shadows?  How far
> > off usable was it, and did it only work with your terrain engine?
> It was decidedly "demo" quality.  But it was part of the model code,
> not the terrain engine.  Doing shadows on terrain is sort of a 2D
> problem, and actually a little simpler (computationally faster, if not
> algorithmically easier) than doing a full-on general shadow
> implementation.
> Basically, there are two general techniques for doing shadows with 3D
> hardware:
> The first is to draw the object casting the shadow into a
> 1-bit-plus-depth "shadow buffer" from the point of view of the light
> source.  You then use this buffer as a modulating texture for the
> light source when drawing the objects on which the shadow falls.  This
> is a relatively straightforward process (although it requires some
> form of rendering to a texture, which wasn't standardized in OpenGL
> until recently) and works fast.  The problems are that the resolution
> is limited to what you pick for the texture, so you can see pixelation
> effects if the viewer is close to an object which is "far" from the
> shadow caster.  More seriously, you cannot use this technique for
> objects which cast shadows on *themselves* since the depth information
> in the shadow buffer isn't precise enough.
> Stenciling is the other trick.  This is a geometric technique where
> you draw the "shadow volume" of an object into the stencil buffer.
> For each triangle, for example, you draw a tetrahedron containing its
> vertices and a vertex projected "infinitely" far away from the light
> source.  You then use some nifty tricks involving the stencil buffer
> to tell which screen pixels are lit by the light source.  This is a
> great technique, and works correctly in a very nice general way for
> every surface on the screen.
> It's also abysmally slow when implemented naively.  Every (!) polygon
> ends up beign drawn as a big swath from its real position to one edge
> of the screen.  This eats fill rate like there's no tomorrow.
> Production implementation need to do lots of bookeeping work to
> optimize the shadow volume such that only polygons on the silouette of
> the object are drawn (others are essentially useless).  This is the
> part I didn't finish. :)
> Andy

Thanks for the info.  It's something I've wondered about, in a 'how do they do 
that?' sort of way, but it's a bit beyond my programming ability to do 
anything practical about it.

Something to look forwards to, perhaps;)


Flightgear-devel mailing list

Reply via email to