2 uniform float smoothness;
7 void gradcurves(float t, out float over, out float under);
9 #define HALF_PI 1.570796326794897
13 const vec2 pix_sz = vec2(1.0 / 512.0, 1.0 / 256.0); // TODO: uniform
15 vec2 uv = gl_TexCoord[0].st;
16 float dist = texture2D(tex, uv).a;
18 float dfdu = texture2D(tex, uv + vec2(pix_sz.x, 0.0)).a - dist;
19 float dfdv = texture2D(tex, uv + vec2(0.0, pix_sz.y)).a - dist;
20 vec2 grad = normalize(vec2(dfdu, dfdv));
22 float glyph = smoothstep(0.47 - smoothness, 0.47 + smoothness, dist);
23 float outline = smoothstep(0.54 - smoothness, 0.54 + smoothness, dist);
25 // --- face gradients ---
26 float t = local_pt.y / height;
28 float c_over, c_under;
29 float tlow = min(2.0 * t, 1.0);
30 gradcurves(tlow, c_over, c_under);
31 vec3 color_low = vec3(c_over, c_under, c_over);
33 float thigh = max(2.0 * t - 1.0, 0.0);
34 gradcurves(thigh, c_over, c_under);
35 vec3 color_high = vec3(c_under, c_under, c_over);
37 vec3 color = mix(color_low, color_high, step(0.5, t));
39 // --- bevel gradients ---
40 float bv_shade = mod(1.0 * dot(grad, normalize(vec2(1.0, 1.0))) * 0.5 + 0.5, 1.0);
42 gradcurves(1.0 - bv_shade, c_over, c_under);
43 vec3 bv_col = vec3(c_under, c_under, c_over);
45 gl_FragColor.rgb = mix(bv_col, color, outline);
46 gl_FragColor.a = glyph;
49 void gradcurves(float t, out float over, out float under)
51 over = cos(t * HALF_PI);
52 under = cos(t * HALF_PI + HALF_PI) + 1.0;