View Full Version : Using stencil lightvolumes in forward rendering?

10-13-2014, 12:15 PM

I wonder if this can be done. Suppose you have a relatively simple game geometry with small local lightsources. Suppose also that the engine can clip many polygons (but not all) the light cannot reach.

Can I do the following?

Draw the entire visible scene.
for every lightsource in the scene:

tell the engine to clip as many polygons as possible not lit by current light and render the rest (not in the output colorbuffer).
draw a sphere around the lightsource, use stencil test to increment it's value when the viewray enters the sphere and to decrement when it reaves it. This is pretty much the same process that is often done for deferred shading. Again this must not be in the final color output of the fragment shader (using a "null" fragment shader for example).
draw all polygons lit by the light again. invoke light shader to draw the light on every pixel the inside the sphere (determined by stencil) and this time output it to the final gl_FragColor.

Now I realize this means I have to render all lit parts of the geometry at least twice - probably more. The thing is when the geometry is not too complex and the engine can quickly sort out parts of the geometry not lit by a lightsource maybe this approach is faster on GPUs with small memory bandwidth like Intel HD Graphics.

Or maybe there is a flaw in my thinking and this cannot be done at all the way I imagine?

Any Ideas???