Sign in to follow this  

2d lighting system

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to find/think of a way to do a dynamic lighting system in a 2d game, but haven't been having much luck. The methods I've thought of seem to always have major flaws, and it's important that items would be able to know whether or not they could "see" things in shadows, based on the level of light in the area. For example, one idea, just having shadowed versions of all of the tiles, with further thought, seems like it would require a ton of tiles drawn with different shadow shapes, or have all of the lights the same size, or look like a checkerboard. A non pre-drawn way of doing the lighting, if possible, seems like it would be better. Any suggestions or info on a way to have portions of sprites darkened/made transparent without darkening the entire sprite would be extremely appreciated. Thanks in advance for any help/suggestions, BmBobo

Share this post


Link to post
Share on other sites
I successfully used a simplified version of that method in my game Last Dawn.

You can see it in action here: Last Dawn

I used mine to do shafts of light rather than shadows, but the same applies in reverse.

Basically, have 2 sets of tiles, one lighted set and one dark set. Draw the dark set to the screen, then draw rectangles from the corners of light occluding objects away from the light source, into the stencil buffer with colour writing off. This will create stencil regions for what is in shadow.

Then turn colour writing back on, and draw the lighted tiles over the screen with a stencil function so that they only draw in the non-shadowed areas, as specified by the stencil buffer.

sorry if that's confusing, but it's the basic gist of it.

Share this post


Link to post
Share on other sites

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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