+1 vote

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

in Engine by (428 points)

1 Answer

+1 vote

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 https://docs.godotengine.org/en/stable/tutorials/2d/2d_lights_and_shadows.html 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.

by (24 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.