• Advertisement
Sign in to follow this  

2D Tile Based Lighting

This topic is 1901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Hi Xanther,

I have experimented with a lighting system and I would suggest you at least take a look at it:
[url="http://www.gamedev.net/blog/1385/entry-2254898-added-fog-of-war-via-lighting/"]Journal entry[/url]
(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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement