+1 vote

In Godot 3.0.6 (Ubuntu & Win7), I try to recreate the light effect from Darkwood, but with CanvasItemMaterial -> Light Mode -> Light Only, the shown part becomes transparent.

I tried to use a custom shader, but it doesn't make any diffrence...

shadertype canvasitem;
void fragment() {
// For all fragments in the light
COLOR = vec4(texture(TEXTURE, UV).rgb, 1.0);
else {
// For all other fragments
COLOR = vec4(texture(TEXTURE, UV).rgb, 0.0);

Is there a problem with the 2d lighting system or am i missing something?

Thanks in advance for any help.

in Engine by (33 points)
retagged by

1 Answer

+2 votes
Best answer

I've figured it out!

You have to change the Light2D mode to mix (not add !) and by using a shader, like the one above, process every pixel's color as you want, based on if the light passes through it or not. And shadows work just fine! And for a sprite to be visible only under light, just set it's material mode to light only.

Also if you want a light to affect only specific sprites, you have to set the Range --> Item Cull Mask level of the Light2D to the corresponding level of the sprites.

More information on this very helpful article:

by (33 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.