iDevGames Forums
2d shadow blending problems - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: 2d shadow blending problems (/thread-8733.html)

2d shadow blending problems - tesil - Mar 16, 2011 05:08 PM

I used this article... create a 2d game with dynamic hard shadows with lights.

Here's how rendering works:

For each light:
(1) clear the color buffer's alpha components to all 0s (by drawing calling glColorMask(0,0,01) and drawing a screen sized quad with a 0 alpha)
(2) draw light map (using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA))
(3) draw shadow geometry for the current light (basically just draw polygons containing an alpha of 0.0 using (using glBlendFunc(GL_ZERO,GL_ZERO).
(4) draw sprites (using glBlendFunc(GL_DST_ALPHA, GL_ONE)).

(For simplicities sake assume that 0.0 is my default ambient light setting)

The problem is, say you have 2 lights overlapping one another. Light one is drawn first, followed by it's shadows (light 1's shadow polygon s will write 0.0s into the alpha buffer), followed by light 2 (which will brighten light 1's shadow polygons), followed by light 2's shadow polygons which will be 0.0 (darker than light 1's shadow polygons) since light 2 and its shadows are drawn after light 1 and no other light will be drawn after light 2. So you see light 2 ends up with darker shadows than light 1.

I'm sure I'm probably overlooking something obvious, but not matter how hard I try I cannot seem to overcome this problem.

RE: 2d shadow blending problems - Skorche - Mar 17, 2011 10:12 AM

You have to render the shadow mask separately. You don't render the light, then darken it by the shadows. You render a mask for the shadows, then use this mask to prevent the lighting from ever showing up in the first place.