#version 450
layout(location = 0) in vec2 vUV;
layout(location = 1) in vec4 vClip;
layout(std140, binding = 0) uniform Globals {
    mat4  uVP;
    vec3  uTint;
    float uHasView;
    float uGlowPass;
    float uTime;
};
layout(binding = 1) uniform sampler2D uView;
layout(location = 0) out vec4 FragColor;
void main() {
    float r = length(vUV);
    if (uGlowPass > 0.5) {
        float a = (1.0 - smoothstep(1.0, 1.42, r)) * smoothstep(0.90, 1.01, r);
        float flicker = 0.88 + 0.12 * sin(uTime * 2.3 + atan(vUV.y, vUV.x) * 3.0);
        FragColor = vec4(uTint * 1.7 * flicker, a * 0.75);
        return;
    }
    if (r > 1.0) discard;
    vec2 s = (vClip.xy / vClip.w) * 0.5 + 0.5;
    vec3 through = texture(uView, clamp(s, vec2(0.0005), vec2(0.9995))).rgb;
    float swirl = 0.5 + 0.5 * sin(r * 11.0 - uTime * 2.6 + atan(vUV.y, vUV.x) * 2.0);
    vec3 fill = mix(uTint * (0.14 + 0.46 * swirl), through, uHasView);
    float wash = smoothstep(0.80, 1.0, r);
    float lip  = smoothstep(0.945, 1.0, r);
    vec3 col = mix(fill, uTint * 1.30, wash * 0.85);
    col = mix(col, mix(uTint, vec3(1.0), 0.6) * 1.7, lip);
    col += uTint * wash * 0.22;
    FragColor = vec4(col, 1.0);
}
