Calculating 2D tiled lights (additive behaviour of multiple sources)

Hey all!

I’m trying to wrap my head around the additive nature of attenuated light sources in a tiled 2D scenario.

Pictures!

Here’s the current method of calculating a light source (linked because they’re too big for this post):
Imgur

The light at the source point is at maximum brightness. The light then bleeds off around 30% per tile’s distance from the source, ending when the result is zero or below.

Assuming that I’m starting with a blank light map (zero light), how do I get to a situation where I’m accurately ‘blending’ other cell’s light levels?

Consider the following example:
Imgur

Here, multiple light sources intersect. This is a photoshop mockup using alphas that roughly represent the same light levels I’m actually using in-game. But the principle seems to work well - the alphas that overlap seem to add together to give a blended equivalent.

Is the principle as simple as adding the result of a light source calculation to the existing cell’s light level? So assuming a blank ‘zero’ light starting point, I simply add each light source’s attenuated light level to the cell’s existing level?

I feel like I’m missing something, so hopefully some guidance will help steer me away from certain disaster!

Thanks!

That seems right, I use a similar technique in my game Astrofirm (see gif). Just have a minimum light level and a maximum light level then have each rendered tile’s light add a fraction their neighbors light level to itself until the fraction is too small to add to new tiles, but you must make sure that the light level variable is reset back to the minimum light level each frame or it will just continue rise. You can even have dynamic shadows if you make solid blocks not transmit much light.

Lights in Astrofirm (sorry if hard to see):

http://giant.gfycat.com/IckyYearlyAtlanticspadefish.gif

A few differences:

  1. My lighting algorithm uses RGB as the indication of brightness instead of Alpha values in order to support colored lights. (I recommend this way where total higher RGB values indicate brighter light and individual RGB values indicate color.
  2. My bleeding might be a bit exaggerated :wink:

Hope this helped at all.

That’s brilliant! Just the kind of reply I was hoping for!

I’m really pleased that I was heading along the right lines.

Currently, I’m apply a blanket floating-point modifier to the RGB color value of each tile. Each quad’s vertex colours are all multiplied by the light intensity thusly:


glColor3f(red * intensity, green * intensity, blue * intensity);

I’m guessing that supporting coloured lights, as you say, is no different than multipliying the individual color components by actual light color components. Intensity is the floating point light level for that tile (between 1 and zero).

I’ll give it a try, thanks!