Added option to render bars on left/right sides, see #64

This commit is contained in:
Jarcode
2018-10-03 17:45:48 -07:00
parent 8102f99683
commit e4b16cdbb6
2 changed files with 28 additions and 12 deletions

View File

@@ -1,18 +1,18 @@
/* center line thickness (pixels) */ /* Center line thickness (pixels) */
#define C_LINE 1 #define C_LINE 1
/* width (in pixels) of each bar */ /* Width (in pixels) of each bar */
#define BAR_WIDTH 4 #define BAR_WIDTH 4
/* width (in pixels) of each bar gap */ /* Width (in pixels) of each bar gap */
#define BAR_GAP 2 #define BAR_GAP 2
/* outline color */ /* Outline color */
#define BAR_OUTLINE #262626 #define BAR_OUTLINE #262626
/* outline width (in pixels, set to 0 to disable outline drawing) */ /* Outline width (in pixels, set to 0 to disable outline drawing) */
#define BAR_OUTLINE_WIDTH 0 #define BAR_OUTLINE_WIDTH 0
/* Amplify magnitude of the results each bar displays */ /* Amplify magnitude of the results each bar displays */
#define AMPLIFY 300 #define AMPLIFY 300
/* Alpha channel for Bars color */ /* Alpha channel for bars color */
#define ALPHA 0.7 #define ALPHA 0.7
/* How strong the gradient changes */ /* How strong the gradient changes */
#define GRADIENT_POWER 60 #define GRADIENT_POWER 60
@@ -26,4 +26,7 @@
#define INVERT 0 #define INVERT 0
/* Whether to flip the output vertically */ /* Whether to flip the output vertically */
#define FLIP 0 #define FLIP 0
/* Whether to mirror output along `Y = X`, causing output to render on the left side of the window */
/* Use with `FLIP 1` to render on the right side */
#define MIRROR_YX 0

View File

@@ -29,20 +29,33 @@ out vec4 fragment;
#define PI 3.14159265359 #define PI 3.14159265359
void main() { void main() {
float dx = (gl_FragCoord.x - (screen.x / 2));
#if FLIP == 0 #if MIRROR_YX == 0
float d = gl_FragCoord.y; #define AREA_WIDTH screen.x
#define AREA_HEIGHT screen.y
#define AREA_X gl_FragCoord.x
#define AREA_Y gl_FragCoord.y
#else #else
float d = screen.y - gl_FragCoord.y; #define AREA_WIDTH screen.y
#define AREA_HEIGHT screen.x
#define AREA_X gl_FragCoord.y
#define AREA_Y gl_FragCoord.x
#endif #endif
float nbars = floor((screen.x * 0.5F) / float(BAR_WIDTH + BAR_GAP)) * 2;
float dx = (AREA_X - (AREA_WIDTH / 2));
#if FLIP == 0
float d = AREA_Y;
#else
float d = AREA_HEIGHT - AREA_Y;
#endif
float nbars = floor((AREA_WIDTH * 0.5F) / float(BAR_WIDTH + BAR_GAP)) * 2;
float section = BAR_WIDTH + BAR_GAP; /* size of section for each bar (including gap) */ float section = BAR_WIDTH + BAR_GAP; /* size of section for each bar (including gap) */
float center = section / 2.0F; /* half section, distance to center */ float center = section / 2.0F; /* half section, distance to center */
float m = abs(mod(dx, section)); /* position in section */ float m = abs(mod(dx, section)); /* position in section */
float md = m - center; /* position in section from center line */ float md = m - center; /* position in section from center line */
if (md < ceil(float(BAR_WIDTH) / 2) && md >= -floor(float(BAR_WIDTH) / 2)) { /* if not in gap */ if (md < ceil(float(BAR_WIDTH) / 2) && md >= -floor(float(BAR_WIDTH) / 2)) { /* if not in gap */
float p = int(dx / section) / float(nbars / 2); /* position, (-1.0F, 1.0F)) */ float p = int(dx / section) / float(nbars / 2); /* position, (-1.0F, 1.0F)) */
p += sign(p) * ((0.5F + center) / screen.x); /* index center of bar position */ p += sign(p) * ((0.5F + center) / AREA_WIDTH); /* index center of bar position */
/* Apply smooth function and index texture */ /* Apply smooth function and index texture */
#define smooth_f(tex, p) smooth_audio(tex, audio_sz, p) #define smooth_f(tex, p) smooth_audio(tex, audio_sz, p)
float v; float v;