I'm not sure if this can be done, but it's worth it. I use a stencil buffer to reduce redundancy for light volumes in deferred rendering using this algorithm (when the camera is out of volume):
- Using a cheap shader, draw back faces with in-depth testing set to LEQUAL, marking them in the stencil buffer.
- Using an expensive lighting shader, paint the front surfaces with the depth set to GEQUAL.
This will only shadow pixels within the volume of light. A problem with this occurs when drawing multiple light sources. Firstly, since changes in the state of the road, it is probably not the best idea to repeatedly switch between a cheap and expensive shader for every light. Ideally, I would like to use all 8 bits of the stencil buffer, providing 8 light volumes with a cheap shader, and then 8 light volumes with an expensive shader. However, problems arise when the light overlaps, as there is no way to determine which element the pixels belong to.
The solution that comes to mind is to use 1 bit in the stencil buffer to the light. So, for light n, mark the n th bit in the stencil buffer in the cheap pass, and then display the pixels with this bit during the expensive pass.
I have not used a stencil buffer before, but from what I am reading, this is not possible. For this to work, I would have to set the pattern buffer using a bitwise OR, and the stencil function should be bitwise I. However, the only operations in the stencil buffer that I see are: KEEP, ZERO, REPLACE, INCR, DECR and INVERT , and the only functions are: NEVER, ALWAYS, LESS, EQUAL, LEFT, HEXAWAL, MORE AND MENU.
Is there a way to somehow get this OR and ANDing behavior using a stencil buffer? And if not, is there an alternative approach to efficient rendering of light volumes?
bit-manipulation opengl volume light stencil-buffer
Gumgo
source share