Monthly Archives: May 2012

Pre-calculated light maps

Overlapping light sources

Times of Sand, a little dive into writing a small somewhat non traditional roguelike game. It will be reasonably easy to pick up and play the game.

A few days ago I added support for precalculated lightmaps. Upon generating the map I use a simple algorithm to calculate the ambient light and hereby minding the distance and radiosity of the light source. In order to calculate overlapping light sources we store this value inside a small two-dimensional table and add the calculated value to this. We are able to store colordata with it as well so it’s possible to have yellow and purple light sources.

lightMap[(y - (distanceToLightSource / 2)) + tY][(x - (distanceToLightSource / 2)) + tX] =
lightMap[(y - (distanceToLightSource / 2)) + tY][(x - (distanceToLightSource / 2)) + tX] +
math.clamp(0, radiosity * ((distanceToLightSource / 2) - math.dist((distanceToLightSource / 2),(distanceToLightSource / 2), tX, tY)), 100)

As visible in the screenshot, the player ofcourse has to be colored as well. We just subtract the light map value for the matching tile and that’s taken care of as well. I can start on dungeon generation now.

Advertisements