#version 440

layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;

layout(std140, binding = 0) uniform buf {
    mat4 qt_Matrix;
    float qt_Opacity;
    float time;
    float intensity; // 0.0 to 1.0, controlled by Audio Amplitude
};

float rand(vec2 co) {
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main() {
    vec2 uv = qt_TexCoord0;
    
    // 1. Base Noise (subtle grain)
    float noise = rand(uv + vec2(time * 0.01, 0.0));
    
    // 2. Radial Glow (bright center, fading to edges)
    vec2 center = vec2(0.5, 0.5);
    float dist = distance(uv, center);
    
    // Glow strength based on intensity (audio amplitude)
    // Higher intensity = brighter, wider glow
    float glowRadius = 0.3 + (intensity * 0.4); // Radius grows with volume
    float glow = 1.0 - smoothstep(0.0, glowRadius, dist);
    glow = pow(glow, 2.0); // Sharpen the falloff
    
    // 3. Color the glow (warm white/cyan tint)
    vec3 glowColor = vec3(0.8, 0.9, 1.0); // Slight cyan tint
    
    // 4. Combine noise + glow
    vec3 finalColor = mix(vec3(noise), glowColor, glow * intensity);
    
    fragColor = vec4(finalColor, 1.0) * qt_Opacity;
}
