Merge pull request #97 from arch1t3cht30/graph_tweaks
Anti-aliasing and better joining for the graph module
This commit is contained in:
@@ -13,8 +13,17 @@
|
||||
#define DRAW_OUTLINE 0
|
||||
/* 1 to draw edge highlight, 0 to disable */
|
||||
#define DRAW_HIGHLIGHT 1
|
||||
/* Whether to anti-alias the border of the graph, creating a smoother curve.
|
||||
This may have a small impact on performance. Note that this only anti-aliases
|
||||
the border, so that the seams between the graph and the outline and/or the
|
||||
highlight (if present) will not be aliased.
|
||||
Note: This requires `xroot` transparency to be enabled since it
|
||||
relies on alpha blending with the background. */
|
||||
#define ANTI_ALIAS 0
|
||||
/* outline color */
|
||||
#define OUTLINE #262626
|
||||
/* 1 to join the two channels together in the middle, 0 to clamp both down to zero */
|
||||
#define JOIN_CHANNELS 0
|
||||
/* 1 to invert (vertically), 0 otherwise */
|
||||
#define INVERT 0
|
||||
|
||||
|
||||
@@ -81,16 +81,31 @@ out vec4 fragment;
|
||||
#define TWOPI 6.28318530718
|
||||
|
||||
float half_w;
|
||||
float middle;
|
||||
highp float pixel = 1.0F / float(screen.x);
|
||||
|
||||
void render_side(in sampler1D tex, float idx) {
|
||||
highp float pixel = 1.0F / float(screen.x);
|
||||
float get_line_height(in sampler1D tex, float idx) {
|
||||
float s = smooth_audio_adj(tex, audio_sz, idx / half_w, pixel);
|
||||
/* scale the data upwards so we can see it */
|
||||
s *= VSCALE;
|
||||
/* clamp far ends of the screen down to make the ends of the graph smoother */
|
||||
s *= clamp((abs((screen.x / 2) - gl_FragCoord.x) / screen.x) * 48, 0.0F, 1.0F);
|
||||
|
||||
float fact = clamp((abs((screen.x / 2) - gl_FragCoord.x) / screen.x) * 48, 0.0F, 1.0F);
|
||||
#if JOIN_CHANNELS > 0
|
||||
fact = -2 * pow(fact, 3) + 3 * pow(fact, 2); /* To avoid spikes */
|
||||
s = fact * s + (1 - fact) * middle;
|
||||
#else
|
||||
s *= fact;
|
||||
#endif
|
||||
|
||||
s *= clamp((min(gl_FragCoord.x, screen.x - gl_FragCoord.x) / screen.x) * 48, 0.0F, 1.0F);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void render_side(in sampler1D tex, float idx) {
|
||||
float s = get_line_height(tex, idx);
|
||||
|
||||
/* and finally set fragment color if we are in range */
|
||||
#if INVERT > 0
|
||||
float pos = float(screen.y) - gl_FragCoord.y;
|
||||
@@ -106,6 +121,9 @@ void render_side(in sampler1D tex, float idx) {
|
||||
|
||||
void main() {
|
||||
half_w = (screen.x / 2);
|
||||
|
||||
middle = VSCALE * (smooth_audio_adj(audio_l, audio_sz, 1, pixel) + smooth_audio_adj(audio_r, audio_sz, 0, pixel)) / 2;
|
||||
|
||||
if (gl_FragCoord.x < half_w) {
|
||||
render_side(audio_l, LEFT_IDX);
|
||||
} else {
|
||||
|
||||
100
shaders/graph/3.frag
Normal file
100
shaders/graph/3.frag
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
in vec4 gl_FragCoord;
|
||||
|
||||
#request uniform "screen" screen
|
||||
uniform ivec2 screen; /* screen dimensions */
|
||||
|
||||
#request uniform "prev" tex
|
||||
uniform sampler2D tex; /* screen texture */
|
||||
|
||||
out vec4 fragment; /* output */
|
||||
|
||||
#include "@graph.glsl"
|
||||
#include ":graph.glsl"
|
||||
|
||||
/* Moves toward the border of the graph, gives the
|
||||
y coordinate of the last colored pixel */
|
||||
float get_col_height_up(float x, float oy) {
|
||||
float y = oy;
|
||||
#if INVERT > 0
|
||||
while (y >= 0) {
|
||||
#else
|
||||
while (y < screen.y) {
|
||||
#endif
|
||||
vec4 f = texelFetch(tex, ivec2(x, y), 0);
|
||||
if (f.a <= 0) {
|
||||
#if INVERT > 0
|
||||
y += 1;
|
||||
#else
|
||||
y -= 1;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if INVERT > 0
|
||||
y -= 1;
|
||||
#else
|
||||
y += 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/* Moves toward the base of the graph, gives the
|
||||
y coordinate of the first colored pixel */
|
||||
float get_col_height_down(float x, float oy) {
|
||||
float y = oy;
|
||||
#if INVERT > 0
|
||||
while (y < screen.y) {
|
||||
#else
|
||||
while (y >= 0) {
|
||||
#endif
|
||||
vec4 f = texelFetch(tex, ivec2(x, y), 0);
|
||||
if (f.a > 0) {
|
||||
break;
|
||||
}
|
||||
#if INVERT > 0
|
||||
y += 1;
|
||||
#else
|
||||
y -= 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
void main() {
|
||||
fragment = texelFetch(tex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0);
|
||||
|
||||
#if ANTI_ALIAS > 0
|
||||
|
||||
if (fragment.a <= 0) {
|
||||
bool left_done = false;
|
||||
float h2;
|
||||
float a_fact = 0;
|
||||
|
||||
if (texelFetch(tex, ivec2(gl_FragCoord.x - 1, gl_FragCoord.y), 0).a > 0) {
|
||||
float h1 = get_col_height_up(gl_FragCoord.x - 1, gl_FragCoord.y);
|
||||
h2 = get_col_height_down(gl_FragCoord.x, gl_FragCoord.y);
|
||||
fragment = texelFetch(tex, ivec2(gl_FragCoord.x, h2), 0);
|
||||
|
||||
a_fact = clamp(abs((h1 - gl_FragCoord.y) / (h2 - h1)), 0.0, 1.0);
|
||||
|
||||
left_done = true;
|
||||
}
|
||||
if (texelFetch(tex, ivec2(gl_FragCoord.x + 1, gl_FragCoord.y), 0).a > 0) {
|
||||
if (!left_done) {
|
||||
h2 = get_col_height_down(gl_FragCoord.x, gl_FragCoord.y);
|
||||
fragment = texelFetch(tex, ivec2(gl_FragCoord.x, h2), 0);
|
||||
}
|
||||
float h3 = get_col_height_up(gl_FragCoord.x + 1, gl_FragCoord.y);
|
||||
|
||||
a_fact = max(a_fact, clamp(abs((h3 - gl_FragCoord.y) / (h2 - h3)), 0.0, 1.0));
|
||||
}
|
||||
|
||||
fragment.a *= a_fact;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user