Added aliasing to radial module
This commit is contained in:
6
render.c
6
render.c
@@ -146,7 +146,8 @@ static GLuint shaderload(const char* rpath,
|
|||||||
"#version %d\n"
|
"#version %d\n"
|
||||||
"#define UNIFORM_LIMIT %d\n"
|
"#define UNIFORM_LIMIT %d\n"
|
||||||
"#define PRE_SMOOTHED_AUDIO %d\n"
|
"#define PRE_SMOOTHED_AUDIO %d\n"
|
||||||
"#define SMOOTH_FACTOR %.6f\n";
|
"#define SMOOTH_FACTOR %.6f\n"
|
||||||
|
"#define XROOT %d\n";
|
||||||
|
|
||||||
struct glsl_ext ext = {
|
struct glsl_ext ext = {
|
||||||
.source = raw ? NULL : map,
|
.source = raw ? NULL : map,
|
||||||
@@ -164,7 +165,8 @@ static GLuint shaderload(const char* rpath,
|
|||||||
size_t blen = strlen(header_fmt) + 42;
|
size_t blen = strlen(header_fmt) + 42;
|
||||||
GLchar* buf = malloc((blen * sizeof(GLchar*)) + ext.p_len);
|
GLchar* buf = malloc((blen * sizeof(GLchar*)) + ext.p_len);
|
||||||
int written = snprintf(buf, blen, header_fmt, (int) shader_version, (int) max_uniforms,
|
int written = snprintf(buf, blen, header_fmt, (int) shader_version, (int) max_uniforms,
|
||||||
gl->smooth_pass ? 1 : 0, (double) gl->smooth_factor);
|
gl->smooth_pass ? 1 : 0, (double) gl->smooth_factor,
|
||||||
|
gl->copy_desktop ? 1 : 0);
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
fprintf(stderr, "snprintf() encoding error while prepending header to shader '%s'\n", path);
|
fprintf(stderr, "snprintf() encoding error while prepending header to shader '%s'\n", path);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
/* center radius (pixels) */
|
/* center radius (pixels) */
|
||||||
#define C_RADIUS 64
|
#define C_RADIUS 128
|
||||||
/* center line thickness (pixels) */
|
/* center line thickness (pixels) */
|
||||||
#define C_LINE 1.5
|
#define C_LINE 2
|
||||||
/* outline color */
|
/* outline color */
|
||||||
#define OUTLINE vec4(0.20, 0.20, 0.20, 1)
|
#define OUTLINE vec4(0.20, 0.20, 0.20, 1)
|
||||||
/* number of bars (use even values for best results) */
|
/* number of bars (use even values for best results) */
|
||||||
#define NBARS 92
|
#define NBARS 180
|
||||||
/* width (in pixels) of each bar*/
|
/* width (in pixels) of each bar*/
|
||||||
#define BAR_WIDTH 3.5
|
#define BAR_WIDTH 3.5
|
||||||
/* outline color */
|
/* outline color */
|
||||||
@@ -21,3 +21,9 @@
|
|||||||
#define ROTATE (PI / 2)
|
#define ROTATE (PI / 2)
|
||||||
/* Whether to switch left/right audio buffers */
|
/* Whether to switch left/right audio buffers */
|
||||||
#define INVERT 0
|
#define INVERT 0
|
||||||
|
/* Aliasing factors. Higher values mean more defined and jagged lines.
|
||||||
|
Note: aliasing does not have a notable impact on performance, but requires
|
||||||
|
`xroot` transparency to be enabled since it relies on alpha blending with
|
||||||
|
the background. */
|
||||||
|
#define BAR_ALIAS_FACTOR 1.2
|
||||||
|
#define C_ALIAS_FACTOR 1.8
|
||||||
|
|||||||
@@ -29,6 +29,17 @@ out vec4 fragment;
|
|||||||
#define PI 3.14159265359
|
#define PI 3.14159265359
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
|
#if XROOT > 0
|
||||||
|
#define APPLY_FRAG(f, c) f = vec4(f.rgb * f.a + c.rgb * (1 - f.a), max(c.a, f.a))
|
||||||
|
fragment.a = 0;
|
||||||
|
#else
|
||||||
|
#define APPLY_FRAG(f, c) f = c
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* To handle jagged edges, we alias in the shader by using alpha layer blending.
|
||||||
|
Alpha layer blending is only applied when `xroot` transparency is enabled. */
|
||||||
|
|
||||||
float /* translate (x, y) to use (0, 0) as the center of the screen */
|
float /* translate (x, y) to use (0, 0) as the center of the screen */
|
||||||
dx = gl_FragCoord.x - (screen.x / 2),
|
dx = gl_FragCoord.x - (screen.x / 2),
|
||||||
dy = gl_FragCoord.y - (screen.y / 2);
|
dy = gl_FragCoord.y - (screen.y / 2);
|
||||||
@@ -36,8 +47,13 @@ void main() {
|
|||||||
float d = sqrt((dx * dx) + (dy * dy)); /* distance */
|
float d = sqrt((dx * dx) + (dy * dy)); /* distance */
|
||||||
if (d > C_RADIUS - (float(C_LINE) / 2.0F) && d < C_RADIUS + (float(C_LINE) / 2.0F)) {
|
if (d > C_RADIUS - (float(C_LINE) / 2.0F) && d < C_RADIUS + (float(C_LINE) / 2.0F)) {
|
||||||
fragment = OUTLINE;
|
fragment = OUTLINE;
|
||||||
return;
|
#if XROOT > 0
|
||||||
} else if (d > C_RADIUS) {
|
fragment.a *= ((float(C_LINE) / 2.0F) - abs(d - C_RADIUS)) * C_ALIAS_FACTOR;
|
||||||
|
#else
|
||||||
|
return; /* return immediately if there is no alpha blending available */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (d > C_RADIUS) {
|
||||||
const float section = (TWOPI / NBARS); /* range (radians) for each bar */
|
const float section = (TWOPI / NBARS); /* range (radians) for each bar */
|
||||||
const float center = ((TWOPI / NBARS) / 2.0F); /* center line angle */
|
const float center = ((TWOPI / NBARS) / 2.0F); /* center line angle */
|
||||||
float m = mod(theta, section); /* position in section (radians) */
|
float m = mod(theta, section); /* position in section (radians) */
|
||||||
@@ -56,25 +72,43 @@ void main() {
|
|||||||
else v = smooth_f(audio_r); /* right buffer */
|
else v = smooth_f(audio_r); /* right buffer */
|
||||||
v *= AMPLIFY; /* amplify */
|
v *= AMPLIFY; /* amplify */
|
||||||
#undef smooth_f
|
#undef smooth_f
|
||||||
d -= C_RADIUS + (float(C_LINE) / 2.0F); /* offset to fragment distance from inner circle */
|
/* offset to fragment distance from inner circle */
|
||||||
|
#if XROOT > 0
|
||||||
|
#define ALIAS_FACTOR (((BAR_WIDTH / 2) - abs(ym)) * BAR_ALIAS_FACTOR)
|
||||||
|
d -= C_RADIUS; /* start bar overlapping the inner circle for blending */
|
||||||
|
#else
|
||||||
|
#define ALIAS_FACTOR 1
|
||||||
|
d -= C_RADIUS + (float(C_LINE) / 2.0F); /* start bar after circle */
|
||||||
|
#endif
|
||||||
if (d <= v - BAR_OUTLINE_WIDTH) {
|
if (d <= v - BAR_OUTLINE_WIDTH) {
|
||||||
|
vec4 r;
|
||||||
#if BAR_OUTLINE_WIDTH > 0
|
#if BAR_OUTLINE_WIDTH > 0
|
||||||
if (abs(ym) < (BAR_WIDTH / 2) - BAR_OUTLINE_WIDTH)
|
if (abs(ym) < (BAR_WIDTH / 2) - BAR_OUTLINE_WIDTH)
|
||||||
fragment = COLOR;
|
r = COLOR;
|
||||||
else
|
else
|
||||||
fragment = BAR_OUTLINE;
|
r = BAR_OUTLINE;
|
||||||
#else
|
#else
|
||||||
fragment = COLOR;
|
r = COLOR;
|
||||||
#endif
|
#endif
|
||||||
|
#if XROOT > 0
|
||||||
|
r.a *= ALIAS_FACTOR;
|
||||||
|
#endif
|
||||||
|
APPLY_FRAG(fragment, r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if BAR_OUTLINE_WIDTH > 0
|
#if BAR_OUTLINE_WIDTH > 0
|
||||||
if (d <= v) {
|
if (d <= v) {
|
||||||
fragment = BAR_OUTLINE;
|
#if XROOT > 0
|
||||||
|
vec4 r = BAR_OUTLINE;
|
||||||
|
r.a *= ALIAS_FACTOR;
|
||||||
|
APPLY_FRAG(fragment, r);
|
||||||
|
#else
|
||||||
|
APPLY_FRAG(fragment, BAR_OUTLINE);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fragment = vec4(0, 0, 0, 0); /* default frag color */
|
fragment = APPLY_FRAG(fragment, vec4(0, 0, 0, 0)); /* default frag color */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user