summaryrefslogtreecommitdiffstats
path: root/src/Runtime/ogl-runtime/res/effectlib/distancefieldtext_dropshadow_core.frag
blob: 51aae5a7addbe8d54cbe1415a300cf45bc514f25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
in vec2 sampleCoord;
in vec2 shadowSampleCoord;
in vec4 normalizedTextureBounds;

out vec4 fragColor;

uniform sampler2D _qt_texture;
uniform vec4 color;
uniform vec4 shadowColor;

void main()
{
    float shadowDistance = texture(_qt_texture,
                                   clamp(shadowSampleCoord,
                                         normalizedTextureBounds.xy,
                                         normalizedTextureBounds.zw)).r;
    float shadowDistanceD = fwidth(shadowDistance);
    float shadowAlpha = smoothstep(0.5 - shadowDistanceD, 0.5, shadowDistance);
    vec4 shadowPixel = color * shadowColor * shadowAlpha;

    float textDistance = texture(_qt_texture,
                                 clamp(sampleCoord,
                                       normalizedTextureBounds.xy,
                                       normalizedTextureBounds.zw)).r;
    float textDistanceD = fwidth(textDistance);
    float textAlpha = smoothstep(0.5 - textDistanceD, 0.5, textDistance);
    vec4 textPixel = color * textAlpha;

    fragColor = mix(shadowPixel, textPixel, textPixel.a);
}