Hiii, question about color swapping shaders! I'm creating a game that resembles a Game Boy game and I would like a way to swap out different palettes in a settings menu or with a keystroke. So instead of the colors being gray, they could be shades of green or 4 separate hues.
Does anyone know how to implement a (quick) palette swap feature? There are tutorials on this, but they are for Godot 3 and don't work with 4. I'm only kinda familiar with GDScript, not at all with C#.
I think it would be possible (though not ideal) to have all the colors be separate sprites layered on top of each other, then you can use .modulate to change the colors for alllll the sprites. But I think a shader would be better.
EDIT
Fixed! Someone figured it out!
shader_type canvas_item;
uniform vec4 black : source_color;
uniform vec4 dark : source_color;
uniform vec4 light : source_color;
uniform vec4 white : source_color;
uniform sampler2D screen_texture : hint_screen_texture;
void fragment() {
COLOR = texture(screen_texture,SCREEN_UV);
float rgb_avg = (COLOR.r + COLOR.g + COLOR.b) / 3.0;
if (rgb_avg < 0.25) {COLOR = black;}
else if (rgb_avg < 0.50) {COLOR = dark;}
else if (rgb_avg < 0.75) {COLOR = light;}
else {COLOR = white;}
}
I was also told to (optionally) nest the ColorRect under a CanvasLayer node.