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.

-Jan 12, 2023-
I figured out that my antequated shader isn’t quite so antequated. It turns out that there is a usecase for it if you want fine control over each individual color in the shader, because you can access them via gdscript as shader uniforms. To my knowledge there is no equivalent for individual colors in a gradient.

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

Extensible Color Palette for Vulkan

Related shaders

Extensible Color Palette for Vulkan

Extensible Color Palette

color splash (show only one color)


1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
3 months ago

How does it differs from the WorldEnvironment Color Correction adjustment?