Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
// these are color palettes, basically you have a variable in and it changes color smoothly based on that variable
// Function from Iñigo Quiles
// https://www.shadertoy.com/view/MsS3Wc
// NOTE this is already built into the force
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
6.0)-3.0)-1.0,
0.0,
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}
// to see this function graphed out go to: https://www.desmos.com/calculator/rz7abjujdj
vec3 cosPalette( float t )
{
// please play around with these numbers to get a better palette
vec3 brightness = vec3(0.3);
vec3 contrast = vec3(0.5);
vec3 osc = vec3(0.5,1.0,0.0);
vec3 phase = vec3(0.4,0.9,0.2);
return brightness + contrast*cos( 6.28318*(osc*t+phase) );
}
// this is the same thing but you pass in all the variables yourself
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
vec3 cosPalette( float t , vec3 brightness, vec3 contrast, vec3 osc, vec3 phase)
{
return brightness + contrast*cos( 6.28318*(osc*t+phase) );
}
// to read more about turbo: https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
// in short, its good for colorblindness, getting more deatil (based on human perception), high contrast
// but still smooth interpretation of the in-value
vec3 turboPalette(float x){ // x can be any floating point number that changes, like time or pos.x;
float m = 1.0; // it repeats every 1 unit, because thats the turbo function's range
float t = m - abs(mod(x*20. , (2.*m)) - m);
// this line turns an increasing value into a triangle wave, linear interpolation of length 1 up
// linear interpolation of length 1 down. like this: /\/\/\/\/\/\/\/\/\/\/\/\/\/
// you use const whenever the varible is just using plain old data that wont change
// its more efficient
const vec3 c0 = vec3(0.1140890109226559, 0.06288340699912215, 0.2248337216805064);
const vec3 c1 = vec3(6.716419496985708, 3.182286745507602, 7.571581586103393);
const vec3 c2 = vec3(-66.09402360453038, -4.9279827041226, -10.09439367561635);
const vec3 c3 = vec3(228.7660791526501, 25.04986699771073, -91.54105330182436);
const vec3 c4 = vec3(-334.8351565777451, -69.31749712757485, 288.5858850615712);
const vec3 c5 = vec3(218.7637218434795, 67.52150567819112, -305.2045772184957);
const vec3 c6 = vec3(-52.88903478218835, -21.54527364654712, 110.5174647748972);
return c0+t*(c1+t*(c2+t*(c3+t*(c4+t*(c5+t*c6))))); // this is magic, dont worry about it.
}
// change space functions
// The following are from http://mercury.sexy/hg_sdf/ (modified a lil by char)
// Rotate around a coordinate axis (i.e. in a plane perpendicular to that axis) by angle <a>.
// Read like this: R(p.xz, a) rotates "x towards z".
vec2 rotate(vec2 p, float a) {
return p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
// Repeat around the origin by a fixed angle.
// For easier use, num of repetitions is use to specify the angle.
vec2 modPolar(vec2 p, float repetitions) {
float angle = 2.*PI/repetitions;
float a = atan(p.y, p.x) + angle/2.;
float r = length(p);
float c = floor(a/angle);
a = mod(a,angle) - angle/2.;
p = vec2(cos(a), sin(a))*r;
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment