multiple shadow maps

Started by
6 comments, last by benjamin bunny 19 years, 9 months ago
Correct me if I'm wrong on the first bit: To do a shadow map, I would draw the polygon fully bright, and then blend the shadow map on top using glBlendFunc(GL_DST_COLOR, GL_ZERO) or glBlendFunc(GL_ZERO, GL_SRC_COLOR); However, how would I apply multiple shadow maps? If I want 1 shadow map for 1 light source, and 1 shadow map for another light source, and to be able to turn them on and off independantly?
Advertisement
Quote:Original post by Squirm
Correct me if I'm wrong on the first bit:
To do a shadow map, I would draw the polygon fully bright, and then blend the shadow map on top using glBlendFunc(GL_DST_COLOR, GL_ZERO) or glBlendFunc(GL_ZERO, GL_SRC_COLOR);

Shadows are an absence of light. If you simply blend the shadows over the top of a lit polygon, the effect won't be correct. Usually you'd use a fragment program and render lit fragments to lit areas, and unlit fragments to unlit areas.

Quote:However, how would I apply multiple shadow maps? If I want 1 shadow map for 1 light source, and 1 shadow map for another light source, and to be able to turn them on and off independantly?


You'd use multi-pass rendering to get that effect. If you render the unlit scene first (with just ambient light). Then use a GL_ONE, GL_ONE blend function and for each light, render black for shadowed fragments, and full lighting for unshadowed fragments. BTW, It's a good idea to scale the contribution of each light to avoid the colour buffer becoming saturated.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Quote:Shadows are an absence of light. If you simply blend the shadows over the top of a lit polygon, the effect won't be correct. Usually you'd use a fragment program and render lit fragments to lit areas, and unlit fragments to unlit areas.

I don't know a great deal about fragment programs, or any of the more sophisticated bits, and while I'd like to learn them sometime, perhaps not yet...
However, that aside, Im not blending shadows on top, Im blending them with it, effectively multiplying the lit polygon with the intensity of the light hitting it, which is correct, isn't it?
Quote:You'd use multi-pass rendering to get that effect.

I have done multiple 'lights' using this method, but I don't see how to make it work with multiple shadow maps / light maps. The equation I would need for the second lighting pass would be
"result = dest color + src color * what-the-dest-color-was-before-the-first-lighting-pass"
Quote:However, that aside, Im not blending shadows on top, Im blending them with it

I don't see the distinction here. If I understand you right, the light is still contributing to the final shadow colour, which it shouldn't.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

I draw a pixel and it comes out at 1.0, 0.5, 0.0 (orange)
I have a light map with that pixel at 0.5,0.5,0.5 (dim white light)

The result of blending it with GL_ZERO, GL_SRC_COLOR should be 1.0*0.5,0.5*0.5,0.0*0.5 = 0.5,0.25,0.0 (dim orange)

which is, as far as I can make out, correct. Anywhere which is actually in shadow will have a light map value of 0,0,0 and result in a black pixel.

I'm sure this should all work. I'd write it to prove the point except that's going to have to wait till I get home. My problem arises when the second light map is unable to give me anything other than black for that pixel.
Just to clarify: Are you talking about shadow maps (as in depth maps rendered from the light's POV used to calculate shadows), or light maps, as in (usually pre-baked) quake-style lighting?

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

prebaked quake style lighting. I would appear to be out of date. When I was learning what these were they were called "light maps" but people were beginning to call them "shadow maps" instead because it's more accurate (the "whatever map" you use darkens things, it doesn't brighten them).

Sorry for any confusion :o)
Oh ok. I'm pretty sure the correct term there is light map.

You should probably use multitexturing (see the ARB_multitexture extension) to multiply the lightmap with the underlying texture, so each light is a single pass.

To get multiple lights to work, you'd still probably have to do a separate pass for each light. So, for each pass, you'd use multitexture to combine the appropriate lightmap and diffuse texture, adding the passes together using blending as I mentioned above.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement