2D Dynamic Shadows in Flash w/Box2D
Ok, so I've had a little bit more time this weekend to work on my shadowing stuff. I still haven't fully implemented the optimizations I wanted to( some are in ) but I have made a bit of progress none the less.
My earlier lighting model was based on the idea that I would draw each light seperately into its own renderTarget( bitmapData ) and then erase the areas that the shadow casters affected. Then I would do the same for the shadow overlay with each light. Two passes, one to erase the shadow( a black renderTarget over the scene ) and another to additively blend the lights together.
However, this had problems in itself.. the overlay blend mode I was using produced bleed through of bright colors and didn't show my shadows as well as I thought it did. Turns out the test case I was using was quite a dark texture so that is why it looked ok.
So, scrapped that lighting model and went with a simpler one. Now there is only one pass for the lightmap, and it is blended multiplicatively to the background scene. This produces a much better result and takes half the rendering. That's a win in my book.
Another part of my plan was to leverage the physics engine's broadphase for my lighting manager. That way I could use the physics engine's broadphase to tell me what lights are affecting what shadow geometry. Saves me the trouble of writing my own broadphase and the performance of running two of them at once. I chose Box2D as my physics layer for a couple of reasons. One, I'm familiar with it as I've worked with it lots in the past. Two, its flexible and very full featured. Three, it has an excellent community( of which I like to consider myself part. ) Of course, since I wanted to try the newest version of Box2D I needed to brush up on the API changes. In the process I spent some time updating some of the testBed examples to work with the newest SVN version.
And now, here is another demo to try. Hit SPACE_BAR to turn on or off debug rendering. With it off there are no shadow casters in place... but that is where the game entities would be anyway.
Demo on Next Page

Post new comment