Methods for basic 2d point lights

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
twingravity.net
Prole
Posts: 1
Joined: Thu Jul 12, 2012 9:54 am

Methods for basic 2d point lights

Post by twingravity.net »

I've looked around for simple methods of rendering basic 2d point lights for my game but can't get one to work. I'd like darkness to obscure things far away from light sources and light to fade out gradually as it gets further away from the source. So far I've tried two general methods but neither worked completely. I'd greatly appreciate any advice or examples of how to do this properly.

Drawing darkness with textures

I would draw a dark blue that was slightly transparent over the entire screen to simulate darkness. For the light sources I would use a stencil to cut out holes and then draw a texture of a radial gradient going from transparent to dark blue to simulate the light fading away. This had two issues:

1. When the sources were close to each other the gradient textures would overlap and look wrong.
2. When fading out the darkness into light, the alpha on the stenciled night color (drawn with either a texture or a rectangle) wouldn't change at the same rate as the gradient texture. The gradient would be darker even though their alpha was the same.

Darkness/light as a pixel effect

I got a basic version to work by darkening each pixel but making the alpha lighter as it got closer to the light source. But this only worked with one sourc/point as I couldn't figure out a method to pass a list of light sources to the pixel effect or to make multiple passes to accomodate multiple sources.

Thanks for any advice!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests