PDA

View Full Version : blending multiple shadowmaps



Bruno
01-02-2007, 02:37 PM
Hello,

For a indoor scene i'm using shadowmaps, which is working perfectly.
For one light is working ok, but now i'm in the process of adding more lights, simultaneously.

So, i'm currently doing 1 pass per light.
On the first part of the render, i render the map with everything on(textures,normalmaps per light).

On the second part of the algorithm, i'm rendering the map from the point of view of each light, and projecting him back on the map.
For the first shadowmap, i just blend it with (GL_ZERO, GL_SRC_ALPHA) , but for the second shadowmap or third, i can't get a proper blend.
Can anyone help me on the correct way to mix the diferent shadowmaps ?

thanks,
Bruno

k_szczech
01-02-2007, 03:58 PM
Blending shadowmaps? You meant blending light passes, right? If yes, then proper blending should be (GL_ONE, GL_ONE) since you add each lighting pass to previous passes. The same goes for first lighting pass since you add this lighting pass to previously rendered ambient pass.
If you don't use ambient lighting, then you can disable blending during first lighting pass.

Komat
01-02-2007, 04:39 PM
Originally posted by Bruno:

So, i'm currently doing 1 pass per light.
On the first part of the render, i render the map with everything on(textures,normalmaps per light).

On the second part of the algorithm, i'm rendering the map from the point of view of each light, and projecting him back on the map.
For the first shadowmap, i just blend it with (GL_ZERO, GL_SRC_ALPHA)
If I understand this correctly, you are rendering fully lit scene and then you try to use the shadowmaps of individual lights to darken shadowed parts of that scene.

This way you will never get correct result.

The correct way to do that is start with image that contains only ambient lighting (or black color if no ambient lighting is present) and add contributions of individual lights where contribution of each light is modulated before addition by result of its shadowmap comparison.

Bruno
01-03-2007, 12:57 AM
k_szczech: Thanks, but won't work, tryed it already ;)



Originally posted by Komat:
The correct way to do that is start with image that contains only ambient lighting (or black color if no ambient lighting is present) and add contributions of individual lights where contribution of each light is modulated before addition by result of its shadowmap comparison. [/QB]I'm not sure if i understand what you mean.,
Let me try to explain better what i'm doing..,
Imagine a long corridor.
If no light is present, i just render the corridor with ambient light of 0.3.
However if a light is present, instead i render the map with a pointlight, and my ambient light is calculated in that same shader., so the corridor away from the light is dark, and near the light is all lighted up.
If i want another light, i do the same thing, but i blend the result of the second light on top of the first.
For the shadowmaps, i was going to do the same, but as explained, no luck.
So, can you explain better what do you mean by this ??

and add contributions of individual lights where contribution of each light is modulated before addition by result of its shadowmap comparison.

and how do i do that ?
thanks,
Bruno

CrazyButcher
01-03-2007, 01:23 AM
render into a white texture,
decal blend all shadows,
you will get a white (unshadowed) / grey,black (shadowed) image of the framebuffer

multiply that texture on top of the framebuffer that contained the regular material effects

Komat
01-03-2007, 02:36 AM
So, can you explain better what do you mean by this ??

and add contributions of individual lights where contribution of each light is modulated before addition by result of its shadowmap comparison.
You currently have shader that calculates lighting from single light. When there are multiple lights you are rendering the scene for each light using this shader and use additive blend to combine results from individual lights into the final color.

You need to modify that shader that it also projects the shadowmap for corresponding light and when it determines that the fragment is in the shadow, it will return black instead of the color calculated from the light. If this is the first light which applies the ambient color as well, the shader will return just the ambient color instead of black in that case.

Basically what you are currently trying to do is to remove light from fully lit image in places where the shadow should be. What you need to do is to prevent the addition of light in the area that is inside the shadow.

k_szczech
01-03-2007, 03:28 AM
Blending shadowmaps? You meant blending light passes, right? If yes...
k_szczech: Thanks, but won't work, tryed it alreadyOf course it didn't work. That 'If yes' was the key - you're trying to blend shadowmaps into scene, but you should blend lighting.

Your scheme is probably:
1. Draw scene lighted by light 1
2. Blend shadowmap 1
3. Draw scene lighted by light 2
4. Blend shadowmap 2
(...)

As Komat wrote: This way you will never get correct result.

Your scheme should be:
1. Draw ambient lighting pass
2. Draw scene lighted by light 1 * shadowmap 1
3. Draw scene lighted by light 2 * shadowmap 2

Shadowmaps should not be used to darken pixels after lighting pass. They should be used to modulate lighting pass.