From: John Tsiombikas Date: Wed, 10 Aug 2016 20:26:36 +0000 (+0300) Subject: better dir-link visualization X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=commitdiff_plain;h=47fdbdc2feec8d097d296fe019fbeb653c0b0efc better dir-link visualization --- diff --git a/sdr/chrome_font.p.glsl b/sdr/chrome_font.p.glsl new file mode 100644 index 0000000..9817257 --- /dev/null +++ b/sdr/chrome_font.p.glsl @@ -0,0 +1,52 @@ +uniform sampler2D tex; +uniform float smoothness; +uniform float height; +uniform vec2 pix_sz; + +varying vec2 local_pt; + +void gradcurves(float t, out float over, out float under); + +#define HALF_PI 1.570796326794897 + +void main() +{ + vec2 uv = gl_TexCoord[0].st; + float dist = texture2D(tex, uv).a; + + float dfdu = texture2D(tex, uv + vec2(pix_sz.x, 0.0)).a - dist; + float dfdv = texture2D(tex, uv + vec2(0.0, pix_sz.y)).a - dist; + vec2 grad = normalize(vec2(dfdu, dfdv)); + + float glyph = smoothstep(0.47 - smoothness, 0.47 + smoothness, dist); + float outline = smoothstep(0.54 - smoothness, 0.54 + smoothness, dist); + + // --- 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)); + + // --- bevel gradients --- + float bv_shade = mod(1.0 * dot(grad, normalize(vec2(0.1, 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/chrome_font.v.glsl b/sdr/chrome_font.v.glsl new file mode 100644 index 0000000..27dc8df --- /dev/null +++ b/sdr/chrome_font.v.glsl @@ -0,0 +1,8 @@ +varying vec2 local_pt; + +void main() +{ + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; + local_pt = gl_Vertex.xy; +} diff --git a/sdr/dfont.p.glsl b/sdr/dfont.p.glsl deleted file mode 100644 index 0d4ef4d..0000000 --- a/sdr/dfont.p.glsl +++ /dev/null @@ -1,53 +0,0 @@ -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() -{ - const vec2 pix_sz = vec2(1.0 / 512.0, 1.0 / 256.0); // TODO: uniform - - vec2 uv = gl_TexCoord[0].st; - float dist = texture2D(tex, uv).a; - - float dfdu = texture2D(tex, uv + vec2(pix_sz.x, 0.0)).a - dist; - float dfdv = texture2D(tex, uv + vec2(0.0, pix_sz.y)).a - dist; - vec2 grad = normalize(vec2(dfdu, dfdv)); - - float glyph = smoothstep(0.47 - smoothness, 0.47 + smoothness, dist); - float outline = smoothstep(0.54 - smoothness, 0.54 + smoothness, dist); - - // --- 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)); - - // --- bevel gradients --- - float bv_shade = mod(1.0 * dot(grad, normalize(vec2(0.1, 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 27dc8df..b446ef6 100644 --- a/sdr/dfont.v.glsl +++ b/sdr/dfont.v.glsl @@ -1,8 +1,5 @@ -varying vec2 local_pt; - void main() { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; - local_pt = gl_Vertex.xy; } diff --git a/sdr/glink.p.glsl b/sdr/glink.p.glsl new file mode 100644 index 0000000..0c51278 --- /dev/null +++ b/sdr/glink.p.glsl @@ -0,0 +1,21 @@ +void main() +{ + const vec3 color = vec3(0.2, 0.4, 1.0); + + vec2 uv = gl_TexCoord[0].st; + vec2 pt = uv * vec2(2.0) - vec2(1.0); + + float d_horiz = abs(pt.x); + float d_vert = max(abs(pt.y), 0.0); + + float beam_sharpness = 80.0 * min(uv.y + 0.3, 1.0); + float beam_intensity = 6.0 * (1.0 - uv.y); + + float glow_u = pow(1.0 - smoothstep(0.0, 1.0, d_horiz), beam_sharpness) * beam_intensity; + float glow_v = 1.0 - smoothstep(0.8, 1.0, d_vert); + + float glow = glow_u * glow_v; + + gl_FragColor.rgb = color * glow;// + vec3(0.0, 1.0, 0.0) * step(0.99, max(abs(pt.x), abs(pt.y))); + gl_FragColor.a = 1.0; +} diff --git a/sdr/glink.v.glsl b/sdr/glink.v.glsl new file mode 100644 index 0000000..b446ef6 --- /dev/null +++ b/sdr/glink.v.glsl @@ -0,0 +1,5 @@ +void main() +{ + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff --git a/sdr/glow_font.p.glsl b/sdr/glow_font.p.glsl new file mode 100644 index 0000000..7c55fd1 --- /dev/null +++ b/sdr/glow_font.p.glsl @@ -0,0 +1,19 @@ +uniform sampler2D tex; +uniform float smoothness; +uniform float height; +uniform vec2 pix_sz; + +varying vec2 local_pt; + +void main() +{ + const vec3 color = vec3(0.2, 0.4, 1.0); + + vec2 uv = gl_TexCoord[0].st; + float dist = texture2D(tex, uv).a; + + float glyph = smoothstep(0.5 - smoothness, 0.5 + smoothness, dist); + + gl_FragColor.rgb = color * ((dist - 0.5 - smoothness) * 45.0); + gl_FragColor.a = glyph; +} diff --git a/src/fs.cc b/src/fs.cc index ae5b31a..032fd66 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -26,7 +26,8 @@ static int start_child; static dtx_font *fat_font; #define FAT_FONT_SZ 32 -static unsigned int font_sdr; +static unsigned int glow_link_sdr; +static unsigned int chrome_font_sdr, glow_font_sdr; bool init_fs(const char *path) @@ -51,10 +52,27 @@ bool init_fs(const char *path) } dtx_use_font(fat_font, FAT_FONT_SZ); - if(!(font_sdr = create_program_load("sdr/dfont.v.glsl", "sdr/dfont.p.glsl"))) { + struct dtx_glyphmap *fat_gmap = dtx_get_glyphmap(fat_font, 0); + Vec2 pixsz; + pixsz.x = 1.0 / dtx_get_glyphmap_width(fat_gmap); + pixsz.y = 1.0 / dtx_get_glyphmap_height(fat_gmap); + + if(!(chrome_font_sdr = create_program_load("sdr/chrome_font.v.glsl", "sdr/chrome_font.p.glsl"))) { + return false; + } + set_uniform_float(chrome_font_sdr, "height", dtx_line_height()); + set_uniform_float(chrome_font_sdr, "smoothness", 0.01); + set_uniform_float2(chrome_font_sdr, "pix_sz", pixsz.x, pixsz.y); + + if(!(glow_font_sdr = create_program_load("sdr/dfont.v.glsl", "sdr/glow_font.p.glsl"))) { + return false; + } + set_uniform_float(glow_font_sdr, "smoothness", 0.01); + set_uniform_float2(glow_font_sdr, "pix_sz", pixsz.x, pixsz.y); + + if(!(glow_link_sdr = create_program_load("sdr/glink.v.glsl", "sdr/glink.p.glsl"))) { return false; } - set_uniform_float(font_sdr, "smoothness", 0.01); if(!(cur_node = get_fsnode(path))) { return false; @@ -100,6 +118,8 @@ void draw_fs() rot_xform.rotate(0, 0, time_sec * 0.5); glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); int nchildren = (int)cur_node->children.size(); int ncols = std::min(cur_node->nfiles, max_ncols); @@ -116,8 +136,9 @@ void draw_fs() } } - // ... and draw them - glLineWidth(5.0); + // draw the directory link lines + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + for(int i=0; ichildren[i]; @@ -131,23 +152,46 @@ void draw_fs() xform.rotate_y(angle); xform.translate(0, -0.3, 0); - glUseProgram(0); + glUseProgram(glow_link_sdr); glPushMatrix(); glMultMatrixf(xform[0]); + glDepthMask(0); - glBegin(GL_LINES); + glBegin(GL_QUADS); glColor3f(0.2, 0.3, 0.8); - glVertex3f(0, 0, -0.3); - glVertex3f(0, 0, -2); + glTexCoord2f(0, 0); + glVertex3f(-0.25, 0, 0.05); + glTexCoord2f(1, 0); + glVertex3f(0.25, 0, 0.05); + glTexCoord2f(1, 1); + glVertex3f(0.25, 0, -2.0); + glTexCoord2f(0, 1); + glVertex3f(-0.25, 0, -2.0); glColor3f(1, 1, 1); glEnd(); glPopMatrix(); + glDepthMask(1); + } + + // draw the directory labels + glUseProgram(glow_font_sdr); + col = 0; + for(int i=0; ichildren[i]; + + if(node->type != FSTYPE_DIR) { + continue; + } + + float angle = (float)col++ / (float)(num_dirs - 1) * max_icon_angle - max_icon_angle * 0.5; + draw_node_name(node, angle, -0.3, radius, false); } - glLineWidth(1.0); - // then draw files + // then draw file icons + glDisable(GL_BLEND); + glUseProgram(0); col = 0; for(int i=0; idraw(node); glPopMatrix(); + if(++col >= ncols) { + col = 0; + ++row; + } + } + + // then draw the file labels + glUseProgram(chrome_font_sdr); + col = 0; + row = 0; + for(int i=0; ichildren[idx]; + + if(node->type == FSTYPE_DIR) { + ++num_dirs; + continue; + } + + float angle = icon_angle(col, ncols, max_icon_angle); + draw_node_name(node, angle, row * row_spacing - 0.1, radius, false); if(++col >= ncols) { @@ -204,8 +267,6 @@ static void draw_node_name(FSNode *node, float angle, float ypos, float dist, bo xform.rotate_y(angle); glMultMatrixf(xform[0]); - glUseProgram(font_sdr); - set_uniform_float(font_sdr, "height", line_height); dtx_string(name); glPopMatrix(); }