Color Remap Shader (Palette swapper)

Remaps the colors of any texture using custom gradients or color palettes. Apply 1D gradients, 2D gradient maps, or custom palette images to completely transform the appearance of your sprites. Perfect for palette swapping.

STEPS:

  1. Attach the shader to a sprite material
  2. Once you have the shader compiled, go to the Inspector and add a gradient or texture image

 

I’m starting to learn shaders, so comments and feedback are appreciated. Thank you!

Shader code
shader_type canvas_item;

uniform sampler2D gradient;

void fragment() {
	//1st step: Set the sprite to Gray tones
	float GrayValue = (COLOR.r + COLOR.g + COLOR.b)/3.0;
	COLOR = vec4(GrayValue,GrayValue,GrayValue,1.0);
	
	//2nd step: Swap palette
	vec2 new_uv = vec2(GrayValue);
	vec4 gradient_color = texture(gradient, new_uv);
	COLOR = vec4(gradient_color.rgb,1.0)*COLOR;
	
	//Erase the contour for png images
	vec4 textura = texture(TEXTURE,UV);
	COLOR.a = COLOR.a * textura.a;
}
Live Preview
Tags
color ramp, color swap, gradient, palette swapper
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

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments