chrome letters first attempt
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 7 Aug 2016 04:10:34 +0000 (07:10 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 7 Aug 2016 04:10:34 +0000 (07:10 +0300)
sdr/dfont.p.glsl
sdr/dfont.v.glsl
src/fs.cc

index 890b4ef..cf60f27 100644 (file)
@@ -1,5 +1,12 @@
 uniform sampler2D tex;
 uniform float smoothness;
+uniform float height;
+
+varying vec2 local_pt;
+
+void gradcurves(float t, out float over, out float under);
+
+#define HALF_PI 1.570796326794897
 
 void main()
 {
@@ -15,9 +22,32 @@ void main()
        float glyph = smoothstep(0.47 - smoothness, 0.47 + smoothness, dist);
        float outline = smoothstep(0.54 - smoothness, 0.54 + smoothness, dist);
 
-       float beveldot = max(dot(grad, normalize(vec2(1.0, 1.0))), 0.0);
-       vec3 bevelcol = mix(vec3(0.05, 0.1, 0.6), vec3(1.0, 0.2, 0.8), beveldot);
+       // --- face gradients ---
+       float t = local_pt.y / height;
+
+       float c_over, c_under;
+       float tlow = min(2.0 * t, 1.0);
+       gradcurves(tlow, c_over, c_under);
+       vec3 color_low = vec3(c_over, c_under, c_over);
+
+       float thigh = max(2.0 * t - 1.0, 0.0);
+       gradcurves(thigh, c_over, c_under);
+       vec3 color_high = vec3(c_under, c_under, c_over);
+
+       vec3 color = mix(color_low, color_high, step(0.5, t));
 
-       gl_FragColor.rgb = mix(bevelcol, vec3(1.0), outline);
+       // --- bevel gradients ---
+       float bv_shade = mod(1.0 * dot(grad, normalize(vec2(1.0, 1.0))) * 0.5 + 0.5, 1.0);
+
+       gradcurves(1.0 - bv_shade, c_over, c_under);
+       vec3 bv_col = vec3(c_under, c_under, c_over);
+
+       gl_FragColor.rgb = mix(bv_col, color, outline);
        gl_FragColor.a = glyph;
 }
+
+void gradcurves(float t, out float over, out float under)
+{
+       over = cos(t * HALF_PI);
+       under = cos(t * HALF_PI + HALF_PI) + 1.0;
+}
index b446ef6..27dc8df 100644 (file)
@@ -1,5 +1,8 @@
+varying vec2 local_pt;
+
 void main()
 {
        gl_Position = ftransform();
        gl_TexCoord[0] = gl_MultiTexCoord0;
+       local_pt = gl_Vertex.xy;
 }
index 57f5170..5795cd0 100644 (file)
--- a/src/fs.cc
+++ b/src/fs.cc
@@ -46,8 +46,8 @@ bool init_fs(const char *path)
                dtx_prepare_range(fat_font, FAT_FONT_SZ * 8, 32, 127);
                dtx_calc_font_distfield(fat_font, 1, 8);
                dtx_save_glyphmap("data/fat.glyphmap", dtx_get_glyphmap(fat_font, 0));
-               dtx_use_font(fat_font, FAT_FONT_SZ);
        }
+       dtx_use_font(fat_font, FAT_FONT_SZ);
 
        if(!(font_sdr = create_program_load("sdr/dfont.v.glsl", "sdr/dfont.p.glsl"))) {
                return false;
@@ -142,6 +142,7 @@ void draw_fs()
                glMultMatrixf(xform[0]);
 
                glUseProgram(font_sdr);
+               set_uniform_float(font_sdr, "height", dtx_line_height());
                dtx_string(node->path.get_name());
                glPopMatrix();