I am trying to fade out a Sprite2D by using tween:
@onready var tween
func _ready():
texture = load("res://Player/Sprites/Player.png")
tween = create_tween()
tween.tween_property(self, "modulate.a", 0, 0.25)
tween.set_trans(Tween.TRANS_QUART)
This in itself works perfectly fine and delivers the desired effect.
However, I want to change the color of the texture at the same time using a shader.
shader_type canvas_item;
uniform bool whiten = true;
uniform float mix_weight = 1.0;
void fragment() {
vec4 texture_color = texture(TEXTURE, UV);
if (whiten) {
vec3 white = vec3(1,1,1);
vec3 whitened_texture_rgb = mix(texture_color.rgb, white, mix_weight);
COLOR.rgb = whitened_texture_rgb;
COLOR.a = texture_color.a;
} else {
COLOR = texture_color;
}
}
When this shader is loaded into the sprite, it does apply the white coloring effect to it but the fade from the tween does not appear to work anymore. I assume the alpha value, modulate:a
, during the tweening does not actually get picked up by the texture_color.a
in the shader script. And I just cannot figure out why. I'd highly appreciate some help!
Disclaimer: I got the code from a youtube video about character dash ghosts. And it seems simple enough for me to think I understand it all. But I am also very new to shaders and might be missing something trivial here.