#version 300 es

precision mediump float;
precision mediump sampler2DArray;

uniform sampler2DArray arrayTextureSampler;

in vec2 Texcoord;
in vec3 CharColor;
in vec3 bgColor;
flat in uint CharData;
in float f_showBg;
in float f_pixResX;
in float f_pixResY;

out vec4 fsFragColor;

void main()
{
    float buf = 0.70; // Edge distance
    float gamma = 0.1; // Edge width

    //if ( gl_FragCoord.y < f_pixResY - 100.0 && gl_FragCoord.x < f_pixResX - 200.0) {
        float dist = texture( arrayTextureSampler, vec3(Texcoord, CharData)).r;
        if (dist==0.0 && f_showBg>0.0) fsFragColor =  vec4(bgColor,1.0) * f_showBg;
        else {
            float alpha = smoothstep(buf - gamma, buf + gamma, dist);
            if (f_showBg>0.0) fsFragColor = vec4(CharColor*alpha + (1.0 - alpha)*bgColor, 1.0 );
            else fsFragColor = vec4(CharColor, alpha);
        }
    //}
    //else discard;
}
