2D Tile Based Lighting

Started by
3 comments, last by BeerNutts 11 years, 6 months ago
How would one go about creating a 2d tile based lighting, just like the one in terraria?

Terraria's lighting seems to have more than just one lighting algorithm. Or maybe its custom made? I have no idea. Ive been searching on the internet for a day now looking on how implement such lighting. I just cant get my head around it, the light actually looks for places to travel though, it seems like, in order to light up a cave/tunnel, even if the character is not in field of view of this cave (i.e. cave is around a corner).

If anyone could give me great resources, links, websites, or actually explain what is happening (it doesn't need to be in C#), that would be extremely appreciated as I am starting to get frustrated about this subject. I have implemented line of sight lightning, but most of the time it looks horrible.

Thanks, Xanather.
Advertisement
It probably uses the same method as minecraft uses for torches. The light basically floods the tiles from the source tile, weakening on every jump. Kind of like how you figure out the costs of paths when doing A* pathfinding.

there might also be a separate way to add sunlight (in mc it lights all tiles visible to sky i believe, and treats each such tile and all the air tiles as light sources) and maybe some "real time" GPU side lighting to make it look better (where the tile-spreading lighting would be an approximation for lightness of spaces and the GPU rendered fancy lighting would make it look good if youre lets say carrying a torch)

o3o

You can also make multiple "light" blocks inside one tile. Light block can have 3 bytes for color and a byte for light level.
To make it faster recalculate only if there are moving lights (like torch in hand).

If you use GPU to render fancy lights then you don't need much light blocks. Only for spawning mobs for example...

Be creative and you can make your own lighting engine, even more fancy than terraria has!
Ok thanks for the replies, re-digit probably did the same (made up his own).
Hi Xanther,

I have experimented with a lighting system and I would suggest you at least take a look at it:
Journal entry
(This is for C++, so if you're using something else, it's probably not valid)

For that particular game, it didn't have to worry about caves and shadows, but the lighting engine does have that capability. Check the links in the journal for more information.

Good luck!

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement