Sign in to follow this  
sg

Question about casting 2D shadows on 2D walls

Recommended Posts

sg    122
Hi all, after seeing screens of O-San's awesome isometric mapping I decided this forum would probably be my best bet to find an answer to my quandary :P I'm working on a simple little 2D tile engine in c with OpenGL, with some extra goodies, one of which is dynamic lighting. Here's a shot of what I have now: and here's a render of just the lights: The method I'm using to cast shadows on the floor is an optimized/extended version of that found in this article, which I'm sure a lot of you have seen :) Basically, shadows are projected from the light to boundary points in convex "shadow regions" and then stenciled out. The "wall" tiles are lit according to a normal that is stored with each tile in the map, pretty simple stuff. However, notice how the shadows on the floor don't interact with the normal-lit tiles (for example the small wall is still lit by the green light in spite of being totally covered by a shadow). I'd really like to add this if there's an efficient way to do so, and I could use a kick in the right direction, or maybe just the opinions of a few coders with more experience than I. Ideas I've toyed with: 1) Since the shadows are projected out from one edge (see second shot) I can check to see if the vector from the light to any given tile intersects one of those shadow base edges... not really accurate but might be good for trivial rejection? If a tile "straddles" a shadow edge I can handle that as a special case. 2) By the time the actual geometry for the light is rendered the stencil buffer contains values that mask out the shadow umbra, penumbra, and unshadowed areas. I haven't experimented with it yet but it's possible to copy that stencil buffer and then check its values where the tiles fall. The downside to this is that I can't really detect angle of the shadow this way and that would totally suck for tiles that don't have a normal pointing straight down on the y axis. Any input would be appreciated. Sorry if I didn't give enough background information, I'll clarify anything if need be. Thanks in advance! -Mason edit: totally forgot the article link :P [Edited by - sg on May 15, 2008 6:41:13 AM]

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