0 votes

How can I set the transparency color on godot?

in Engine by (171 points)

2 Answers

0 votes

I don't know if you can set a colour to be transparent, but what you probably want to do is create a transparency channel in your paint program, then make sure to export your png with that transparency.

by (81 points)
0 votes

You can use a shader:

shader_type canvas_item;

uniform vec4 from_color : hint_color;
uniform vec4 to_color : hint_color;

void fragment() {
    vec4 curr_color = texture(TEXTURE, UV);

    if (curr_color == from_color){
        COLOR = to_color;
    }else{
        COLOR = curr_color;
    }
}

the from_color and to_color uniforms are basically exported variables that you can then set in the Shader Param section:

enter image description here

from_color is the color that you want to change in your sprite or whatever. to_color is the color you want from_color to change to. In your case, you can set that to be fully transparent.

by (1,605 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.