From: John Tsiombikas Date: Sun, 7 Aug 2016 04:10:34 +0000 (+0300) Subject: chrome letters first attempt X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=commitdiff_plain;h=d5b4970b66b1d6b4726dd360a452a0b5b3160f22 chrome letters first attempt --- diff --git a/sdr/dfont.p.glsl b/sdr/dfont.p.glsl index 890b4ef..cf60f27 100644 --- a/sdr/dfont.p.glsl +++ b/sdr/dfont.p.glsl @@ -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; +} diff --git a/sdr/dfont.v.glsl b/sdr/dfont.v.glsl index b446ef6..27dc8df 100644 --- a/sdr/dfont.v.glsl +++ b/sdr/dfont.v.glsl @@ -1,5 +1,8 @@ +varying vec2 local_pt; + void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; + local_pt = gl_Vertex.xy; } diff --git a/src/fs.cc b/src/fs.cc index 57f5170..5795cd0 100644 --- 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();