Extensible Color Palette MK 2

This shader converts a greyscale image into a palette controlled image.

Requires Godot 3.5 if you want the new “constant” gradient type.

Disclamer: Most likely already exists. More below **


How to use:

Apply the shader to your image in question.

Use the offsets under the gradient to tell the shader what brightness to look for when picking a color.
Pick your custom colors to map onto your texture.

Here’s a treat, you don’t have to edit shader code unless you want to. Everything is extensible from the shader’s gradient texture parameter.

It (maybe) couldn’t be more simple.


simply better than my previous shader maybe.


uploaded on August 18, 22.

** This was a suggestion made to me to use a gradient texture, rather than distinct uniform variables, which would also do away with the array, making this functional on GLES2. I left the original up because I’m proud of my solution, but I will admit it isn’t the best solution. It does require shader code editing in order to manipulate it.

Shader code
shader_type canvas_item;
uniform sampler2D Colormap : hint_albedo;

void fragment() {
// Get the fragment location
	vec3 location = vec3(UV, 0.0);

// Get the colors from the image at specified location
	vec3 colorIn;
	float alphaIn;
		vec4 TEXTURE_tex_read = texture(TEXTURE, location.xy);
		colorIn = TEXTURE_tex_read.rgb;
		alphaIn = TEXTURE_tex_read.a;

// get the greyscale value through the highest of r, g, and b
	float grey;
		vec3 c = colorIn;
		float max1 = max(c.r, c.g);
		float max2 = max(max1, c.b);
		grey = max2;

// Read the colormap and use the greyscale value to map in the new color.
	vec3 colorOut;
	float alphaOut;
		vec4 n_tex_read = texture(Colormap, vec2(grey, 0.0));
		colorOut = n_tex_read.rgb;
		alphaOut = n_tex_read.a;

// Profit.
	COLOR.rgb = colorOut;
	COLOR.a = alphaIn;

Color, color palette, gradient, palette, retro
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.

More from LiterallyAnyone

Extensible Color Palette

Related shaders

Extensible Color Palette

color splash (show only one color)

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


Inline Feedbacks
View all comments