2 Colour Palette Swap

Swaps 2 Colours

Shader code
shader_type canvas_item;

uniform vec4 pal_source_1 : source_color  = vec4(0.0);
uniform vec4 pal_source_2 : source_color  = vec4(0.0);

uniform vec4 pal_swap_1 : source_color  = vec4(0.0);
uniform vec4 pal_swap_2 : source_color  = vec4(0.0);

void fragment() {
	COLOR = texture(TEXTURE, UV);
	if (COLOR.a > 0.0)
	{
		if(distance(COLOR, pal_source_1) < 0.1)
		{
			COLOR = pal_swap_1;
		}

		if(distance(COLOR, pal_source_2) < 0.1)
		{
			COLOR = pal_swap_2;
		}
	}
}
Tags
Color, color swap, colour, colour swap, palette, palette swap, swap, switch
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

Palette Swap using two textures

Palette Swap (no recolor / recolor)

2D Fire Effect with colour banding

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments