This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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 (159 points)

1 Answer

+2 votes
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 (8,580 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 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.