Shadow Volumes Problems! plz help! NEW!! with screenshots and Demo!

Hello! I have some problems when i draw shadow volumes.
I first implement the shadows like this:

The idea is this:
for each light
end for

everything was correct exept the color of the shadows!
lets say the first light is a red light, the second a green and the third a blue;
the first shadow(from the red light) is correct. it has all the other colors exept the red.
the second shadow(from green) is not correct!it has only the blue color!
and the third shadow(from blue light) is black!

if I had this light colors:
1)yellow 2)blue 3)red 4)pink 5)purple 6)green
look at this:

yellow ------------------------> blue,red,pink,purple,green
blue -------------------------------> red,pink,purple,green
red ------------------------------------> pink,purple,green
pink ----------------------------------------> purple,green
purple ---------------------------------------------> green
green -------------------------------------> nothing = black

how i can fix this problem?
some people said to me to don’t render the scene like this but like this:
for each light
end for

i try this way but i have problem with casting the shadow(no matter the number of the lights) It seems that all the vertices of the shadow are calculated correct but i does not draw correct.
maybe something with stencil going wrong?

this is the code for the new algorithm:

… something else… as you can see in the code i use ARB_fragment_program. The pixel shader does not do any shadow calculation. only Per pixel lighting .

thanks in advanvce!

here is the pack with the demos and screenshots

It is bad approach “darkening lighted scene”. Switch to “lightening dark scene”.


the first or the second way is better to use? and any idea how i can fox this problems?

I had the same problem a few months ago: pic;f=3;t=011712
Hope this helps.

One point that you maybe missed :

you “ADD” each light contribution to the scene.
Meaning, you render the ambient term, and then ADD each light contribution on top of it. you can use additive blending (GL_ONe, GL_ONE) for this. As you can imagine, adding black doesn’t do anything.


SeskaPeel: I disable the fragment program and blending but i forget to paste it! :smiley:

heya!! I am back again! I was some days off…

Here is a zip pack with some screeshots and two versions of my 3dengine. one with the INFINITY value for the shadow volume very small and the other with very big! also you can read the readme file witch is in there!!!

the demos is with the second way:

first draw the depth of the room
then for each light
draw the shadow volume
draw the room with light

the problem for now with this aproach is not the color problems but the shadow volume is not correct and i dont know why!!

DON’T run the demo if you dont have a VGA with Pixel shader v2.0 support!

Do you have silhouette finder? If so, then check your code…


The answer seems simple, and yet I haven’t seen it.

You need to clear the stencil buffer after rendering each light. If you don’t, the shadow from light 1 will appear in light 2 and so on.