Godot Version
Godot 4.2
Question
I have an AnimatedSprite2D with a ShaderMaterial applied. I want to apply an effect to invert the sprite’s colors for a time and then return to normal after a signal is emitted. Using the shader below, I am able to start the inverse effect using a uniform, but if I try to set it back the colors never change.
My Shader:
shader_type canvas_item;
uniform bool applied = false;
void fragment() {
vec4 color = texture(TEXTURE, UV);
if (applied) {
COLOR = vec4(1.0 - color.rgb, color.a);
} else {
COLOR = texture(TEXTURE, UV);
}
}
The code I use to enable/disable the shader:
if invert_colors:
shader_material.set_shader_parameter("applied", true)
func on_revert_colors() -> void:
print("got signal to turn off color inversion")
shader_material.set_shader_parameter("applied", false)
What am I doing wrong?