Efficient 3-line Pixel Palette Shader, Full Alpha Support

Highly expandable, no conditionals bc GPUs hate those. Uses R channel of sprite color. Uses alpha from palette texture, multiplied against alpha from base sprite.

For simplicity, I recommend incrementing R by 25 at a time for each color up to 225, then using a 10×1 palette. do as you will tho

If the blue-green mess hurts your eyes, you can e.g. use indexed palettes in Aseprite to switch between nicer placeholders and our “true” colors.

Shader code
shader_type canvas_item;

uniform sampler2D palette: filter_nearest;

void fragment() {
	float alpha = COLOR.a;
	COLOR = texture(palette, vec2(COLOR.r + .05, .5));
	COLOR.a *= alpha;
}
Tags
Color, palette, palette swap, pixel, pixel-art, sprite
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

Alpha blend

2D Drop Shadow using alpha

Fog of war with alpha cut off as white color

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments