Stencil shadows + Per pixel lighting in shader


this will be very silly question indeed, but I’ve been looking on the internet for about week now, without any success…

I’ve got stencil shadows implemented (without shaders) and per pixel lighting shader implemented. And I want to put it all together…but my problem is that I don’t know how to acess stencil buffer in my lighting shader and I don’t want to pass it as some texture, or do I have to ?

Or is there some way to bypass stencil buffer and use the shadow volumes in my per pixel lighting sgader ?

So can someone please explain this to me or point me to some sources where it is.
Thanks !

With stencil shadows normally you do two passes:

One pass with the light off, then enable stencil test and do a second pass with the light on.

Another tecnhique is to do the first pass with the light on, enable stencil and draw a translucent quad with a hardcoded “shadow color”.

AFAIK you cannot directly access the stencil buffer from a fragment shader.

I can’t access stencil buffer in fragment shader…so how do I get information from it in my lightin shader?

With that second idea you mean something like:
Create a shadow mask -> grey where the shadow is (or shade of grey depending on number of shadows from multiple lights) and white where the light is supposed to be and then blend it over lighted scene…perhaps by passing it to shader…