#version 150

in vec4 vertexColor;

uniform vec4 ColorModulator;
uniform vec2 Center;
uniform float InnerRadius;
uniform float OuterRadius;
uniform float AntiAliasing;

out vec4 fragColor;

void main() {
    float dist = distance(gl_FragCoord.xy, Center);
    float alpha = 0.0;

    // 确保内外半径合理
    if (OuterRadius <= InnerRadius) {
        vec4 color = vertexColor;
        color.a = 0;
        fragColor = color;
    }

    // 计算环形 alpha
    if (dist >= InnerRadius && dist <= OuterRadius) {
        alpha = 1.0;

        // 内边缘抗锯齿
        if (dist < InnerRadius + AntiAliasing) {
            float fade = (dist - InnerRadius) / AntiAliasing;
            alpha *= fade;
        }

        // 外边缘抗锯齿
        if (dist > OuterRadius - AntiAliasing) {
            float fade = 1.0 - (dist - (OuterRadius - AntiAliasing)) / AntiAliasing;
            alpha *= fade;
        }
    }

    vec4 color = vertexColor;
    color.a *= alpha;

    if (alpha > 0.0) {
        fragColor = color * ColorModulator;
    } else {
        discard;
    }
}