How do I remove black backgrounds from a sprite?

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

How do I remove the black and keep the white using shaders?

Keep in mind I am new and text shaders are completely unreadable to me

:bust_in_silhouette: Reply From: LordBoots

If these are saved sprites then I would suggest manually editing them inside of an image editor and set the black to alpha. Save the image as rgba format and you should be good to go.

If you’re looking for a shader that can do this then there’s a few tutorials online already that should get you where you want but you need to keep in mind that every shader you use will suck resources. While this may not be a big issue for 2d games, some people might give you some hassle for wasting resources if you’re able to just edit the images manually.

I found the shader for it

shader_type canvas_item;

uniform vec4 u_color_key : hint_color;
uniform vec4 u_replacement_color : hint_color;
uniform float tolerance : hint_range(0.0, 1.0, 0.01);

void fragment() {
    vec4 col = texture(TEXTURE, UV);
    vec4 d4 = abs(col - u_color_key);
    float d = max(max(d4.r, d4.g), d4.b);
    if(d < tolerance) {
        col = u_replacement_color;
    COLOR = col;

PizzaMaker | 2022-12-03 19:02