Palette Filter For 3D and 2D

To add Just create a canvas layer with a sprite then attach the shader into it. The gradient should be a horizontal gradient texture, you can download one from the internet or use the gradient texture from godot. P.S.: You can get the palletes from Lospec.com

 

Have fun! 🙂

Shader code
shader_type canvas_item;

uniform bool flip ;
uniform sampler2D gradient : hint_black; // It can be whatever palette you want


void fragment(){ 
	vec4 col = texture(SCREEN_TEXTURE,SCREEN_UV);
	
	float lum = dot(col.rgb,vec3(0.2126,0.7152,0.0722)); // luminance
	
	
	col = texture(gradient,vec2(abs(float(flip) - lum),0));
	
	
	COLOR = col;
}
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

Palette Filter and Pixelate combined

Edge Detection (Sobel Filter and Gaussian Blur)

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

Subscribe
Notify of
guest

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
HeroRobb
HeroRobb
3 years ago

This is pretty nice. The only thing I’d mention to anyone is that you need to put a texture (even the godot icon is fine) on the sprite and make it the size of your viewport to work. I figured it out pretty easily, but just in case someone else can’t.

HeroRobb
HeroRobb
3 years ago
Reply to  HeroRobb

Also having the flip parameter for palettes that have have the lighter colors on the left was very convenient.

andy
2 years ago

hey! just letting you know, this shader is really neat and i’ve used it in a game of mine, if that’s ok! (it can be found here if you want to have a look)

elvisish
1 year ago

Is it possible for this to be used on a ViewportContainer as a post-processing effect?

Bombardlos
1 year ago

Had to change SCREEN_TEXTURE to TEXTURE, and SCREEN_UV to UV:

vec4 color = texture(TEXTURE, UV);

(Now mind you I have no idea what I’m doing, it just worked for me)

Bombardlos
1 year ago
Reply to  Bombardlos

Also the flip feature is amazing

JUN
JUN
1 year ago
Reply to  Bombardlos

The only difference is your shader will change your sprite directly

RufflesTeiv
6 months ago

starting with Godot 4, you’ll need to reduce the bit depth to achieve an effect equal to what’s shown in the screenshots, and it will not adjust automatically to the size of the palette.

create a bit_depth uniform variable for changing the bit depth.

uniform uint bit_depth = 4;

and then, after creating the lum variable, reduce it by the bit depth.

float bits = float(bit_depth);
lum = floor(lum*bits)/bits;

then just apply it to the color as normal

RufflesTeiv
6 months ago

in Godot 4, this works really well as a post-processing shader by applying it to a SubViewportContainer, containing a SubViewport

you can also easily make this sprite-based (which is the approach I used to get different palettes for each sprite) by swapping SCREEN_TEXTURE and SCREEN_UV for TEXTURE and UV respectively, and applying the ShaderMaterial to a Sprite2D node

RufflesTeiv
6 months ago
Reply to  RufflesTeiv

and maybe this isn’t news but you can use a GradientTexture1D in place of a .png texture, really makes things easier