Jump to content
  • Advertisement
Sign in to follow this  
Blademasterbobo

2d lighting system

This topic is 4168 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!