View Full Version : shadows / multipass

09-28-2004, 02:52 AM
I recently added stencil shadows to my project and I have a question regarding the various passes needed to render my objects.
For now, I have:
- render depth and ambient (ambient color or grey level image)
- render shadow volumes (only one light)
- render the objects where there is no shadows using as many passes as needed (I only have 2 texture units so I need many passes)

Of course this is not correct because where I have shadows, I don't have the object texture.

Here is what I'd like to do:
- render depth and ambient
- render shadow volumes
- render the "light" where there is no shadows (+bump if needed)
- render the objects "everywhere" without lighting modulated by the frame buffer.

The questions are:
- is it "correct" ?
- how can I get specular using this method ?

thanks in advance.

09-29-2004, 12:26 PM
No this is wrong, and in particular your final modulation by all objects (I assume by albedo of some sort) makes some things like specular impossible.

Here is you need:
- render depth and ambient
for each light
- render shadow volumes for this light
- render the scene with shadow test illuminated by this light

The key to understanding this is that the rendering of each light is a full lighting equation blended to accumulate in the framebuffer with other light contributions. The lighting calculation can include specular and includes material properties and textures, it does not need modulation later by another pass.

The light contribution can include all terms in a single pass or only some terms like abmient or specular, this way you may split the illumination rendering into multiple passes (all stencil tested) to build the final lighting equation result in the framebuffer.

09-29-2004, 10:56 PM
thanks, but I still don't understand how I will be able to see the texture of the shadowed parts of my objects...
Let's say I have a red and blue checker texture applied, and a grey level ambient texture to make the blue parts visible even with no light. How do I get this working ?

I did 3 images with the gimp to show clearly (I hope) what I have and what I'd like to have.
the pictures (http://www.geocities.com/gemelli_d/opengl.htm)


09-30-2004, 12:46 AM
why are you using a gray image for the ambient pass? just use your normal diffuse texture for the ambient pass, at reduced intensity.

09-30-2004, 01:06 AM
In my opinion (I may be wrong) it is easier to create, to update (at runtime), it uses less memory when compressed and in the future it will probably be used to make things glow.

09-30-2004, 01:32 AM
interesting, but i think you're going a bit afield with that. what dorbie desribed is a way to do *correct* lighting (i.e., additive). first, add the ambient light (scaled diffuse map, for example), then add the lights (modulated diffuse map), one at a time.

in the end, all the stenciling does is prevent the addition from taking place in the shadowed areas.

09-30-2004, 02:15 AM
I think you only need one more pass in your ambient part to do everything the way you want it :

- render depth and ambient (ambient color or grey level image)
- modulate with "- render the objects using as many passes as needed (I only have 2 texture units so I need many passes)"

then go on with stencils etc.

But as others said, not sure you ambient level will be really useful.

09-30-2004, 02:18 AM
ok. Thanks to you two, I hope I understand this better. I'll test tonight...

09-30-2004, 02:25 AM
oops, didn't see ZBuffer's post when I did mine...your solution is what I thought I could use to do the things "my way"...thanks too !

10-03-2004, 10:23 PM
finally, it is still unclear...for my "ambient" problem, I did what ZbuffeR explained. What is probably unclear is the way I understand what dorbie said: "the rendering of each light is a full lighting equation blended to accumulate in the framebuffer with other light contributions".

A problematic (at least for me) case:
- a yellow object RGB: {1, 1, 0.5}
- 2 white lights
- the object is completly lit by the 2 lights
with "complete" lighting equation:
- first light: {1, 1, 1} * {1, 1, 0.5} = {1, 1, 0.5} in the framebuffer
- second light: {1, 1, 1} * {1, 1, 0.5} = {1, 1, 0.5} that is added to the framebuffer and gives {1, 1, 1}
my object is white and it's not good.

with the method I "explained" in my first post:
- first light: {1, 1, 1} in the framebuffer
- second light: {1, 1, 1} that is added to the framebuffer (result is still {1, 1, 1})
- unlit object: {1, 1, 0.5} modulated by the framebuffer {1, 1, 0.5} * {1, 1, 1} that gives {1, 1, 0.5}
my object is yellow and I am happy with that.
in the first case, the "light coefficient" applied is in fact {2, 2, 2} and I don't want it to be so high.

What am I missing ? thanks.

10-04-2004, 12:31 AM
Originally posted by gemelli_d:

What am I missing ? thanks.Nothing. Additive blending will have this effect. Without using the accumulation buffer or floating point render targets a few bright lights will cause saturation.

The more common way to deal with this is to reduce the brightness of each light and make sure objects don't receive contribution from too many lights, or add in fall off. Try adding in a light intensity and play with this until the scene looks good.


10-04-2004, 01:28 AM
thanks. I must now decide if I am going to use this method or not...maybe I'll do both of the methods and see what is the best in my particular case.

10-04-2004, 10:28 PM
Just to close this thread, you can see shots of the "additive lighting" version I did (the 2 last shots) here:

Thanks again for the help !