0 votes

I have a sprite that has a transparent background, I want to change its color without changing the background color using shaders

i have a shader but it change the color of the whole sprite

shader_type canvas_item;
uniform vec4 color: hint_color;

void fragment(){
    COLOR = color;
}
Godot version 3.2.3.stable.official
in Engine by (141 points)

1 Answer

+1 vote
Best answer

You want to preserve the transparency of the sprite. Get the original color like this: vec4 og_color = texture (TEXTURE, UV) and then set the alpha of the new color to the alpha of the old color.

by (7,190 points)
selected by

thanks it worked! Can you put a shader in a separate file, attach it to different sprites and choose a separate color for each sprite?

Yes. Right click it in the inspector, make unique, and then save it.

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.