Not sure if this is commonly done, or if there are loads of tutorials hanging around that I can't find using google. However, I'm trying to create effective spot lights for my troops as they walk round the map. Bearing in mind my map is mostly made up of simple blocks and the lighting doesn't have to be super accurate or cast object shadows I was planning on doing the following.
Could anyone let me know if they can see problems and/or faster ways of doing things? Also, is there an easier way to perform multipass rendering in Xith?-- Cut of a mail I was just sending to Endolf --
This is how I'm going to get lighting to look right, its effectively multipass rendering but with a scenegraph.
1) The lit geometry exists within a SharedGroup node, which is linked twice in the scene graph. The links are in an ordered group so they always get rendered in the right order (multipass rendering
2) First the lit geometry is rendered with a dark marterial setting, no transparency. This provides the base layer
3) Next I generate the light volume geometry and render it with the stencil buffer bit set. This effectively masks out the area that should be "lit". In addition the alpha component is written shading away from the light source (this will be used later on).
4) Next I generate the shadow volumes caused bu this light and render it with the stencil operation set to clear the stencil buffer. This effectively unmasks the bits that would be lit but are in shadow.
5) Then the second link to the shared geomtery is rendered. Before this is rendered the appearances are updated. RenderingAttributes are setup so that the geometry is only rendered where the "lit" areas are. The Material colours are set up to be brighter, this will give the lit appearance. Finally the transparency attributes are set up to blend against the alpha that was written earlier. This should shade the geometry against the light that was generated earlier.
This would work for 1 light, additional lights can all be rendered in the same pass by using only single bits in the stencil buffer. So the light A sets bit 1 and the shadows generated from light A unset bit 1. If any bits are left by the time we get to the second set of geometry then the pixel should be lit.----------------------------------------------------------