aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.frag
blob: 9b65e5f79b09e8997c5ef6b7989f1b73b25f54d1 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
varying highp vec2 sampleCoord;
varying highp vec3 sampleFarLeft;
varying highp vec3 sampleNearLeft;
varying highp vec3 sampleNearRight;
varying highp vec3 sampleFarRight;

uniform sampler2D _qt_texture;
uniform lowp vec4 color;
uniform mediump float alphaMin;
uniform mediump float alphaMax;

void main()
{
    highp vec4 n;
    n.x = texture2DProj(_qt_texture, sampleFarLeft).a;
    n.y = texture2DProj(_qt_texture, sampleNearLeft).a;
    highp float c = texture2D(_qt_texture, sampleCoord).a;
    n.z = texture2DProj(_qt_texture, sampleNearRight).a;
    n.w = texture2DProj(_qt_texture, sampleFarRight).a;
#if 0
    // Blurrier, faster.
    n = smoothstep(alphaMin, alphaMax, n);
    c = smoothstep(alphaMin, alphaMax, c);
#else
    // Sharper, slower.
    highp vec2 d = min(abs(n.yw - n.xz) * 2., 0.67);
    highp vec2 lo = mix(vec2(alphaMin), vec2(0.5), d);
    highp vec2 hi = mix(vec2(alphaMax), vec2(0.5), d);
    n = smoothstep(lo.xxyy, hi.xxyy, n);
    c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c);
#endif
    gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w;
}

/*
#extension GL_OES_standard_derivatives: enable

varying highp vec2 sampleCoord;

uniform sampler2D _qt_texture;
uniform lowp vec4 color;
uniform highp float alphaMin;
uniform highp float alphaMax;

void main()
{
    highp vec2 delta = dFdx(sampleCoord);
    highp vec4 n;
    n.x = texture2D(_qt_texture, sampleCoord - 0.667 * delta).a;
    n.y = texture2D(_qt_texture, sampleCoord - 0.333 * delta).a;
    highp float c = texture2D(_qt_texture, sampleCoord).a;
    n.z = texture2D(_qt_texture, sampleCoord + 0.333 * delta).a;
    n.w = texture2D(_qt_texture, sampleCoord + 0.667 * delta).a;
    n = smoothstep(alphaMin, alphaMax, n);
    c = smoothstep(alphaMin, alphaMax, c);
    gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w;
};
*/