shader_type canvas_item;


uniform sampler2D noise_texture : repeat_disable, filter_nearest;

uniform float progress : hint_range(0.0, 1.0) = 0.0;
uniform float edge_softness : hint_range(0.0, 0.5) = 0.0;

void fragment() {
    vec4 sprite_color = texture(TEXTURE, UV);
    float noise_val = texture(noise_texture, UV).r;

    float phase1_progress = clamp(progress * 2.0, 0.0, 1.0);
    
    float phase2_progress = clamp((progress - 0.5) * 2.0, 0.0, 1.0);
    
    float visibility = smoothstep(noise_val - edge_softness, noise_val + edge_softness, phase1_progress);
    
    float color_transition = smoothstep(noise_val - edge_softness, noise_val + edge_softness, phase2_progress);
    
    vec4 white_color = vec4(1.0, 1.0, 1.0, sprite_color.a);
    
    vec4 final_color = mix(white_color, sprite_color, color_transition);
    
    final_color.a *= visibility;
    
    COLOR = final_color;
}