Last active
July 5, 2020 18:58
-
-
Save CharStiles/dc961bc2af0c0aefa7e1420cff1fca79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float getBPMVis(float bpm){ | |
// this function can be found graphed out here :https://www.desmos.com/calculator/rx86e6ymw7 | |
float bps = 60./bpm; // beats per second | |
float bpmVis = tan((time*PI)/bps); | |
// multiply it by PI so that tan has a regular spike every 1 instead of PI | |
// divide by the beat per second so there are that many spikes per second | |
bpmVis = clamp(bpmVis,0.,10.); | |
// tan goes to infinity so lets clamp it at 10 | |
bpmVis = abs(bpmVis)/20.; | |
// tan goes up and down but we only want it to go up | |
// (so it looks like a spike) so we take the absolute value | |
// dividing by 20 makes the tan function more spiking than smoothly going | |
// up and down, check out the desmos link to see what i mean | |
bpmVis = 1.+(bpmVis*0.05); | |
// we want to multiply by this number, but its too big | |
// by itself (it would be too stroby) so we want the number to multiply | |
// by to be between 1.0 and 1.05 so its a subtle effect | |
return bpmVis; | |
} | |
void main() { | |
vec2 pos = uv(); // origin is in center | |
// who remembers SOH CAH TOA ? | |
// tan, given an angle will return the ratio | |
// so if we only have the ratio of position | |
// we use atan to get the angle | |
float angle = atan(pos.y/abs(pos.x+0.01)); | |
// we take the absolute value of x and add a small number to avoid | |
// dividing by zero which is undefined behavior | |
float r = sin(angle + time); | |
// sin returns a number from -1 to 1, and colors are from 0 to 1, so thats | |
// why you only see red on the screen half the time. the angle goes around | |
// the screen, adding time moves it clockwise | |
float bpmVis = getBPMVis(128.); | |
float ringFrequency = 5.; // making this number bigger will increase frequency | |
float g = cos(length(pos*ringFrequency *bpmVis) - time); | |
// the distance (aka length) from the center put in a cos, time moves the | |
// circles in. | |
float b = cos(angle+ cos(length(pos*15.)) + bands.y * 5.); | |
// this combines what we learned in the red and green channels | |
// angle is going through a cos and so is the length, so we see the | |
// blue channel oscillating in both dimensions the polar coordinates give us | |
// here the music effects the place where the phase of the cosine starts | |
vec4 color = vec4(r,g,b,1); | |
gl_FragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment