summaryrefslogtreecommitdiff
path: root/render/fx_renderer/gles2/shaders/stencil_mask.frag
blob: 523adc85b9a6715035f1a17570e94af7f1c9abee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

varying vec2 v_texcoord;

uniform vec2 half_size;
uniform vec2 position;
uniform float radius;

void main() {
    vec2 q = abs(gl_FragCoord.xy - position - half_size) - half_size + radius;
    float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
    float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
    gl_FragColor = mix(vec4(0.0), vec4(1.0), smoothedAlpha);

    if (gl_FragColor.a < 1.0) {
        discard;
    }
}