#version 460
precision mediump float;
out vec4 o;
const float PI = 22./7.;
layout(location = 0) uniform float syncs[7];
layout(location = 8) uniform float fft_output[1024]; // FFT_SIZE / 4
float u_time = syncs[0];

vec3 render(vec2 uv, float time) {
    float pos = syncs[4];
    if (uv.x >= pos && uv.x <= pos+0.01 ) {
        return vec3(1.);
    }
    
    if (uv.x >= 0.0 && uv.x <= 0.01 ) {
        return vec3(abs(syncs[3]*2));
    }
    
    return vec3(0.1, 0.2, 0.3) * abs(syncs[1]*1.2);

}


void main() {
  	vec2 uv = gl_FragCoord.xy * 2. / vec2(1920,1080);
    vec3 col = render(uv, u_time);
    
    // Determine FFT bin index for current x position
    int index = int(floor(uv.x*128.0));
    index = clamp(index, 0, 255);

    // Get the FFT energy (clamped to avoid NaNs or overflow)
    float energy = clamp(fft_output[index], .0, 1.0);

    float bar_height = energy;
    float fade = smoothstep(bar_height, bar_height + 0.02, 1.0 - uv.y);

    vec3 color = vec3(fade);

    o = vec4(color, 1.0);
}
