How do I apply a shader to a node with multiple sprites?

I made a simple palette-change shader, and it works when I apply it to a node-sprite. However my character-node has multiple sprite-nodes, and applying the shader to the character-node itself doesn’t work

shader_type canvas_item;

uniform int player;
uniform vec4 player1[5] : source_color;
uniform vec4 player2[5] : source_color;
uniform vec4 player3[5] : source_color;
uniform vec4 player4[5] : source_color;




bool colorCheck(vec4 color, vec4 test) {
	float threshold = 0.05;
	
	if (test.r > color.r - threshold 
	&& test.r < color.r + threshold
	&&
	test.g > color.g - threshold 
	&& test.g < color.g + threshold
	&&
	test.b > color.b - threshold 
	&& test.b < color.b + threshold)
		{return true;}
	
	return false;}

void fragment() {
	if (player > 1) {
		vec4 pixel = texture(TEXTURE,UV);
		
		for (int c = 0; c < (player1.length()); c++) {
			if (colorCheck (pixel, player1[c])) {
				if (player == 2) {COLOR = player2[c];}
				if (player == 3) {COLOR = player3[c];}
				if (player == 4) {COLOR = player4[c];}
				}
			}
		}
	}

PS: I hope I am posting correctly, please forgive me for any mistakes

Have you tried with CanvasGroup (CanvasGroup — Godot Engine (stable) documentation in English)? CashewOldDew uploaded a video about it some weeks ago and it seems he does something similar of what you are trying to achieve: https://youtu.be/7Bha0jEqec0?si=HkkUc7mn6pPfBYYx&t=207

1 Like

Thanks!! However, it worked in the editor, but in-game it shows a big white square instead.

Should I make a different forum post?

Okay so I got it to show under certain conditions, but the palette suddenly changes to wrong values depending on… if the character is holding a gun (project-specific obviously), and it renders in the wrong order, and it applies to the gun for some reason. Also, black becomes transparent, and if I set black on the palette, I get a huge black square around the sprites. Oh god

You could also try adding the shader to each sprite and use a script to manage the color change for all of them. It may not be as elegant, but it may be a little easier to implement.

That actually worked. Thank you so much!