Page 1 of 1

Combine inverted stencil and normal stencil

Posted: Sun May 18, 2014 5:15 pm
by SCARD
Hi guys!

I'm trying to implement a lighting engine that can draw shadows and reflections of polygons. This is how it basically works:

1. render the scene unlit into canvas
2. render the unlit canvas into the backbuffer with an ambient color
3. for each lightsource the unlit scene is rendered additive on top of the backbuffer with an inverted stencil that draws shadow polygons of some shadowcasters (convex polygons)

until now everything works quite well but here comes my problem:

4. each lightsource casts reflections on some sides of the convex polygons. these are rendered by drawing the unlit canvas with a stencil that draws the reflection polygon.

this also works quite well but if i want to draw the shadows of those reflections i would need an inverted stencil that again draws the shadow polygons for the reflections. If you first active the normal stencil and than activate the inverted stencil only the inverted stencil is active.

Is there a way to combine the two stencils or do i have to rethink my relfection rendering?