Color Replacer

Change any color on canvas_item based on the desired color order.

Shader code
shader_type canvas_item;

const int COLOR_COUNT = 6;

uniform vec4 colors[COLOR_COUNT] : source_color;
uniform vec4 replace_colors[COLOR_COUNT] : source_color;
uniform float thresholds[COLOR_COUNT];

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

    for (int i = 0; i < COLOR_COUNT; i++) {
        float dist = length(tex_color.rgb - colors[i].rgb);

        if (dist < thresholds[i]) {
            tex_color.rgb = replace_colors[i].rgb;
            break;
        }
    }

    COLOR = tex_color;
}
Live Preview
Tags
change, change-color, Color, color-changer
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted