How can I make a lighting system like Terraria?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jujumumu

I want to make a lighting system like Terrarias. How can I do that. I have never done any lighting.

:bust_in_silhouette: Reply From: JTE

The best way to handle Terraria-like tile lighting that I’ve found so far is actually to simply add another TileMap layer which uses a special TileSet that only contains various simulated “light levels” ranging from transparent to solid black (or whichever color and density you want your absolute darkest setting to be). We will call this TileMap the “LightMap”. You can experiment using a CanvasItemMaterial or ShaderMaterial on the “LightMap” to try and get better mixing results.

If your game has dynamic terrain, you’ll need to write a script for the “LightMap” to automatically populate itself based on the contents of the terrain’s TileMap, depending on how far away each tile is from the nearest open space or light source.

As far as I can tell, Godot Engine’s built-in 2D lighting system can only be either solidly occluded or entirely unhindered, not “fading away one step at a time” as Terraria handles it, nor does it include any forms of “ambient sky light” emanating from the open spaces in the background. This is going to be something you’ll largely have to program yourself.

If you want to use colored or animated lights, you might have some luck mixing the two techniques together, by attaching colored Light2D nodes to relevant objects (see 2D lights and shadows — Godot Engine (stable) documentation in English to set up Light2D nodes if you’d like to try this), but otherwise you’ll likely have to figure out color mixing with a shader or try adding even more “LightMap” layers of specific colors.