Palette Swap (Textureless)
How to use
Make sure the color count matches the amount of colors you want to replace.
Tolerance let’s you choose how strong the swap should be, it should be at least 0.001 for the palette swap to be visible.
The Target Colors are the colors that come from the texture, the replace colors is the new colors that should be applied. Make sure that the index of your desired color matches the index of the other color!
To toggle this shader, use Shader Active
Shader code
shader_type canvas_item;
render_mode unshaded;
uniform vec4 target_colors[20] : source_color;
uniform vec4 replace_colors[20] : source_color;
uniform int color_count : hint_range(0, 20); // number of active color swaps
uniform float tolerance : hint_range(0, 1);
uniform bool shader_active = true; // you’ll change this from your script
void fragment() {
vec4 tex_color = texture(TEXTURE, UV);
if (shader_active) {
for (int i = 0; i < color_count; i++) {
if (distance(tex_color.rgb, target_colors[i].rgb) < tolerance) {
tex_color.rgb = replace_colors[i].rgb;
break;
}
}
}
COLOR = tex_color;
}
