2d shadow blending problems

Posts: 11
Joined: 2011.02
Post: #1
I used this article...


...to 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.
Quote this message in a reply
Posts: 1,487
Joined: 2002.09
Post: #2
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.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Replacing edges with degenerate quads (for shadow volumes) Coyote 9 13,973 Jan 15, 2010 07:08 PM
Last Post: Coyote
  Shadow Mapping - Self-Shadowing Z-Fighting Artifacts Bachus 16 36,143 Feb 11, 2009 12:24 PM
Last Post: arekkusu
  GPU shadow volume extrusion with GLSL TomorrowPlusX 12 20,340 Jan 24, 2007 03:21 PM
Last Post: JoNo21
  general blending versus texture blending questions WhatMeWorry 2 7,694 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  Help! shadow map bug in NVIDIA! dfmoore 13 11,625 Nov 1, 2005 07:26 PM
Last Post: OneSadCookie