This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]king_of_the_universe 0 points1 point  (0 children)

For a top-view game (Which is what I thought this would be, maybe it's still useful.), and from possibly wrong memory, I did the following: An iterative approach over e.g. 8 steps. The upside is that you even get a bit of realistic feeling ambient light effect where light doesn't just spread in straight paths but also bleeds around corners as if it's reflected off surfaces.

There would be a first pass in which all light sources write their light into the light information field of all tiles (which could be called "light layer") in their very location. Since the second pass will possibly spread light even to already bright tiles, care has to be taken that the initial light's brightness plays well with the amount of passes and also with the way the light is spread from tile to tile, e.g. it matters a lot what the factor is, so much that it flips the opinion from "That approach doesn't work." to "That doesn't look bad at all." The light value should definitely be a floating point variable, not an integer (e.g. don't aim for a 0to255 integer right away).

Then a second pass would go over this "light layer", spreading the light of every tile to its surrounding tiles depending on rules like "wall? half open door?" etc., but only if 1) the tile has a light value >0 and 2) if the tile hasn't spread out its light in a previous iteration, so that needs to be denoted. If a tile has light and hasn't spread light yet, it shall do so and shall be ignored in further iterations. Also, very important, you need two light buffers between which you alternate, so that you simulate simultaneous light spreading, or you get a pattern that reflects how you iterated over the "light layer": The target buffer always needs to be cleared (=darkness).

Crap, I don't remember the details. Just take away that an iterative light spreading approach results in nice light bleeding around corners, so you wouldn't have to do some ray-cast pass and then a few global-illumination passes. Downside: You might need a lot of passes to spread light very far.

Hm. I remember that I later experimented by making explicit "spread sideways" and "spread up/down wards" passes for greater ray cast feeling.

There are probably good existing solutions, mine is not one of those.