Godot Version
4.2.2
Question
I was needing multiple shaders on an AnimatedSprite2D and saw that there’s only one shader slot in the Material tab. Is there anything I can do to add multiple shadermaterials or should I just find a workaround? Thanks for any feedback.
One canvas item one material. You will probably need to write a custom shader. Or you can have multiple passes with different materials. It depends on your goals.
Yea, I’m asking because I made a shader that changes a color on the Sprite2D and I need more of those to change each color individually.
well if you setup your coloring on the sprite to say pure red, pure blue, pure green you can do a pixel color test to change its color.
vec4 pixel = texture(TEXTURE, uv);
// red test
if (pixel.r == 1.0){
pixel = new_color()
}
else if ( pixel.g == 1.0){
// green
} else if (pixel.b == 1.0){
// blue
{
If you want seperate shaders you can add a next pass in the inspector. but you will have to set the alpha to 0 otherwise it will redraw some parts over the first shader. I think it best to just do it in one shader.
I guess you could get smart and have uniforms for the test colors and sample them in the editor, that way you wouldn’t have to recolor your sprite.
uniform vec4 test_color1: source_color;
void fragment() {
vec4 pixel = texture(TEXTURE, uv);
// color test
if (pixel == test_color1){
pixel = new_color()
} else if ...
}
1 Like
It’s fine now, I found a color swapping shader with palettes for Godot. Thank you for your help though!