Sign in to follow this  
Squirm

multiple shadow maps

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this