shader_type canvas_item;

uniform float intensity : hint_range(0.0, 1.0) = 0.0;
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;

void fragment() {
    vec2 uv = SCREEN_UV;

    // Subtle distortion — wavy lines, stronger at higher intensity
    float distort_x = sin(uv.y * 35.0 + TIME * 1.8) * 0.003 * intensity;
    float distort_y = cos(uv.x * 28.0 + TIME * 1.2) * 0.002 * intensity;

    // Sample screen with slight RGB split for chromatic aberration feel
    float split = 0.003 * intensity;
    vec4 r = texture(screen_texture, uv + vec2(distort_x + split, distort_y));
    vec4 g = texture(screen_texture, uv + vec2(distort_x,         distort_y));
    vec4 b = texture(screen_texture, uv + vec2(distort_x - split, distort_y));
    vec4 screen = vec4(r.r, g.g, b.b, 1.0);

    // Vignette — darken edges
    vec2 center = uv - 0.5;
    float vignette = 1.0 - smoothstep(0.25, 0.75, length(center) * 1.6);
    screen.rgb *= mix(1.0, vignette, intensity * 0.6);

    // Green spore tint
    vec3 spore_tint = vec3(0.05, 0.45, 0.12);
    screen.rgb = mix(screen.rgb, screen.rgb * spore_tint * 2.2, intensity * 0.35);

    // Slight brightness pulse
    float pulse = 1.0 + sin(TIME * 1.5) * 0.04 * intensity;
    screen.rgb *= pulse;

    COLOR = screen;
}
