1 varying mediump vec2 vTexCoord;
3 uniform mediump float uGlowBoundary;
4 uniform mediump vec2 uOutlineParams;
5 uniform lowp vec4 uOutlineColor;
6 uniform lowp vec4 uShadowColor;
7 uniform mediump vec2 uShadowOffset;
8 uniform lowp vec4 uGlowColor;
9 uniform lowp float uDoOutline;
10 uniform lowp float uDoShadow;
11 uniform lowp float uDoGlow;
13 uniform sampler2D sTexture;
14 uniform lowp vec4 uColor;
18 // sample distance field
19 mediump float smoothing = 0.5;
21 mediump float distance = texture2D(sTexture, vTexCoord).a;
22 mediump float smoothWidth = fwidth(distance);
23 mediump float alphaFactor = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
28 mediump float alpha = uColor.a * alphaFactor;
29 lowp vec4 rgb = uColor;
33 mediump float outlineWidth = uOutlineParams[1] + smoothWidth;
34 mediump float outlineBlend = smoothstep(uOutlineParams[0] - outlineWidth, uOutlineParams[0] + outlineWidth, distance);
35 alpha = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, distance);
36 rgb = mix(uOutlineColor, uColor, outlineBlend);
41 rgb = mix(uGlowColor, rgb, alphaFactor);
42 alpha = smoothstep(uGlowBoundary, smoothing, distance);
46 color = vec4(rgb.rgb, alpha);
49 else // (uDoShadow > 0.0)
51 mediump float shadowDistance = texture2D(sTexture, vTexCoord - uShadowOffset).a;
52 mediump float inText = alphaFactor;
53 mediump float inShadow = smoothstep(smoothing - smoothWidth, smoothing + smoothWidth, shadowDistance);
55 // inside object, outside shadow
60 // inside object, outside shadow
61 else if ((inText != 0.0) && (inShadow == 0.0))
66 // outside object, completely inside shadow
67 else if ((inText == 0.0) && (inShadow == 1.0))
71 // inside object, completely inside shadow
72 else if ((inText != 0.0) && (inShadow == 1.0))
74 color = mix(uShadowColor, uColor, inText);
75 color.a = uShadowColor.a;
77 // inside object, inside shadow's border
78 else if ((inText != 0.0) && (inShadow != 0.0))
80 color = mix(uShadowColor, uColor, inText);
81 color.a *= max(inText, inShadow);
83 // inside shadow's border
84 else if (inShadow != 0.0)
89 // outside shadow and object