Stencil shadows + Per pixel lighting in shader
Hello,
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 !
The stencil process should work regardless of the shader. What API are you using, and how are you drawing?
If you just do the stencil pass as before, but bind your shader instead of setting the fixed-function states before drawing the visible light, what errors do you get?
Provided that you do it the normal way, 1 draw ambient, 2 draw stencil occluders, 3 draw additive lighting on top of the ambient. If that's not how you do it, you might want to try it this way. You are talking about shadow volumes right?
If you just do the stencil pass as before, but bind your shader instead of setting the fixed-function states before drawing the visible light, what errors do you get?
Provided that you do it the normal way, 1 draw ambient, 2 draw stencil occluders, 3 draw additive lighting on top of the ambient. If that's not how you do it, you might want to try it this way. You are talking about shadow volumes right?
Hmm...thanks for hints, this got me thinking...
I do steps 1.) and 2.) in my shadow implementation (yes we are talking about shadow volumes).
Hmm...maybe the problem will be that I do the complete lighting computation (ambient+diffuse+specular so on) in my per pixel lighting shader. Well so how do I do that 3.) step ? Wouldn't it be enough to turn on my lighting shader on the 1.) ambient pass ?
maybe Iam too confused, please stay with me...
p.s. I use OpenGL ...
I do steps 1.) and 2.) in my shadow implementation (yes we are talking about shadow volumes).
Hmm...maybe the problem will be that I do the complete lighting computation (ambient+diffuse+specular so on) in my per pixel lighting shader. Well so how do I do that 3.) step ? Wouldn't it be enough to turn on my lighting shader on the 1.) ambient pass ?
maybe Iam too confused, please stay with me...
p.s. I use OpenGL ...
The best way is generally to first draw your scene with a dark color, then the shadow volume, and then draw the light color where the stencil test says there are no shadows. This is generally the correct way, as you add light to wherever the light reaches. It also works nicely for multiple lights, you just redraw the shadow volumes from the next light, and add the light from it on top of the previous light. (Use additive blending, GL_ONE, GL_ONE).
So if all your shadows should be at color (0.5, 0.5, 0.5) for example, you first draw the whole scene with (0.5, 0.5, 0.5) ambient lighting, then the shadow volume, then with additive blending draw the actual light on top with stencil testing, so that it's only added to places that are not in shadow.
So if all your shadows should be at color (0.5, 0.5, 0.5) for example, you first draw the whole scene with (0.5, 0.5, 0.5) ambient lighting, then the shadow volume, then with additive blending draw the actual light on top with stencil testing, so that it's only added to places that are not in shadow.
but this leads us to my first question...how to determine where to draw light and where not to...I don't have stencil buffer information in shader.
So I won't be able to blend the lighting only on places where I want it to. And to make this more complicated, in my lighting shader I compute bump mapping and parallax mapping ... so I want to add these effects on shadowed areas as well.
hmm...
or maybe I can do something like this:
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...but wouldn't this be an overkill ? or is this completely stupid idea?
anyway thanks a lot for helping!
So I won't be able to blend the lighting only on places where I want it to. And to make this more complicated, in my lighting shader I compute bump mapping and parallax mapping ... so I want to add these effects on shadowed areas as well.
hmm...
or maybe I can do something like this:
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...but wouldn't this be an overkill ? or is this completely stupid idea?
anyway thanks a lot for helping!
Quote:Original post by thomas3711You don't need the stencil information in the shader. Set up the shader test to discard all pixels with the stencil bit set, and then the shader will only render where the stencil bit is not set.
but this leads us to my first question...how to determine where to draw light and where not to...I don't have stencil buffer information in shader.
Quote:Original post by thomas3711glEnable(GL_STENCIL_TEST), and then figure out what glStencilFunc() you need...
hmmm and how do I do that ? (I use OpenGL an Cg)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement