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
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

Extensible Color Palette (Gradient Maps) Now with Palette Blending!

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

Palette Limiter Shader

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Alex
Alex
3 years 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 =(

creesee
creesee
1 year ago

How do I use it? How to apply colors to palette?