how to change the color of a sprite without touching the background using a shader

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Timofey

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;
}
:bust_in_silhouette: Reply From: exuin

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.

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?

Timofey | 2021-02-22 06:39

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

exuin | 2021-02-22 07:54