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.
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
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.
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.
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.
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.