Jump to content
  • Advertisement
Sign in to follow this  
LAURENT*

How to make spot lights in darkness for 2D games

This topic is 830 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

Conceptually how do you create spot lights for a 2D game? I need these spot lights to reveal what's behind the darkness.

Share this post


Link to post
Share on other sites
Advertisement

That tutorial gave me ideas but it is not what I had in mind. The spot light would need have an frontal view so it would be like a circle not an 2D lighting engine. The best example I could think of is flashing a flashlight in a dark room on the wall and only seeing the circle of light where the flashlight is pointed.  

Share this post


Link to post
Share on other sites

The spot light would need have an frontal view so it would be like a circle not an 2D lighting engine. The best example I could think of is flashing a flashlight in a dark room on the wall and only seeing the circle of light where the flashlight is pointed.  

It reminded me of Hostages (Operation Jupiter). See the page Hostage: Rescue Mission (1990) screenshots - MobyGames for some visual examples. Do you have one of the result you would like to get ?

 

As the rendering you describe seems simple a technique would be to have 2 rooms, a light one and a dark one. By default the last is displayed. To render the effect apply a circular mask over the light room at the searchlight coordinates. The method is the same than for a transparent sprite. Multiple spots can be rendered, the mask smoothed…

Edited by gdjm

Share this post


Link to post
Share on other sites

1) render your scene to a render texture

2) render your spotlight mask to another render texture

3) compose the two for your final scene with a shader that multiplies the two texture samples

 

If whatever API you're using doesn't support custom shaders, then you can probably achieve step 2/3 with the right blend states too:

2) render your spotlight mask to the frame buffer

3) render your render texture from part 1 to the frame buffer with a blend state that does "source color" * "dest color".

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!