Palette Shader

Converts an image to a color pallete.

Shader code
shader_type canvas_item;
void fragment(){
	vec3 palette[] = {vec3(0)}; // Can be any list of RGB colors, but there must be at least one.
	vec3 color = texture(TEXTURE,UV).rgb;
	vec3 new_color = palette[0];
	for (int i = 0; i<pallete.length(); i++){
		if (distance(palette[i],color) < distance(new_color, color)){
			new_color = palette[i];
		}
		COLOR.rgb = new_color;
		COLOR.a  = texture(TEXTURE,UV).a
	}
}
Tags
palette

Related shaders

Earthbound-like battle background shader w/scroll effect and palette cycling

Palette shader (lospec compatible)

Palette Filter For 3D and 2D

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.
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Alex
Alex
3 months ago

Nice job but, at line 6 you put ‘pallete’ and the correct is ‘palette’
Also the sprite get black and I can´t change the color =(