slightly better?
[vrfileman] / sdr / chrome_font.p.glsl
1 uniform sampler2D tex;
2 uniform float smoothness;
3 uniform float height;
4 uniform vec2 pix_sz;
5
6 varying vec2 local_pt;
7
8 void gradcurves(float t, out float over, out float under);
9
10 #define HALF_PI 1.570796326794897
11
12 void main()
13 {
14         vec2 uv = gl_TexCoord[0].st;
15         float dist = texture2D(tex, uv).a;
16
17         float dfdu = texture2D(tex, uv + vec2(pix_sz.x, 0.0)).a - dist;
18         float dfdv = texture2D(tex, uv + vec2(0.0, pix_sz.y)).a - dist;
19         vec2 grad = normalize(vec2(dfdu, dfdv));
20
21         float glyph = smoothstep(0.47 - smoothness, 0.47 + smoothness, dist);
22         float outline = smoothstep(0.54 - smoothness, 0.54 + smoothness, dist);
23
24         // --- face gradients ---
25         float t = local_pt.y / height;
26
27         float c_over, c_under;
28         float tlow = min(2.0 * t, 1.0);
29         gradcurves(tlow, c_over, c_under);
30         vec3 color_low = vec3(c_over, c_under, c_over);
31
32         float thigh = max(2.0 * t - 1.0, 0.0);
33         gradcurves(thigh, c_over, c_under);
34         vec3 color_high = vec3(c_under, c_under, c_over);
35
36         vec3 color = mix(color_low, color_high, step(0.5, t));
37
38         // --- bevel gradients ---
39         float bv_shade = mod(1.0 * dot(grad, normalize(vec2(0.1, 1.0))) * 0.5 + 0.5, 1.0);
40
41         gradcurves(1.0 - bv_shade, c_over, c_under);
42         vec3 bv_col = vec3(c_under, c_under, c_over);
43
44         gl_FragColor.rgb = mix(bv_col, color, outline);
45         gl_FragColor.a = glyph;
46 }
47
48 void gradcurves(float t, out float over, out float under)
49 {
50         over = cos(t * HALF_PI);
51         under = cos(t * HALF_PI + HALF_PI) + 1.0;
52 }