Skip to content

Instantly share code, notes, and snippets.

@DanielOaks
Last active April 21, 2020 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielOaks/a5ba01f1cd4642d1a0dcb325532925e1 to your computer and use it in GitHub Desktop.
Save DanielOaks/a5ba01f1cd4642d1a0dcb325532925e1 to your computer and use it in GitHub Desktop.

GLSL Shader Bits

Constants

#define pi acos(-1.)
#define tau (2.*pi)

UV Stuff

Standard UV Setups

vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
uv -= 0.5;
uv /= vec2(v2Resolution.y / v2Resolution.x, 1);

Expand Field of View (FoV)

uv *= 1. + dot(uv,uv)*4.; // increase '4' for wider fov

Gamma Correction

This is done right before setting the output colour, corrects gamma for standard CRT screens (all screens use the same messed-up gamma so this is the right thing to do everywhere).

// first method
col = pow(col, vec3(1/2.2));
// second method
col = pow(col, vec3(0.454545454545));

Misc

BPM

float bpm = 140.;
float bpmod = -.01; // -1 to +1, how much to offset the beat by for fine-tuning

float beat = mod((bpm/60.)*(time-(bpm/60.)*bpmod), 4); // 1,2,3,4->

col = mix(vec3(0.), vec3(.1), 1-mod(beat,2.)); // example use, beats 1 and 3 flash

Kick

This produces a really interesting 'stepping' effect when the time is given as t.

float kick(float t, float amt) {return floor(t) + pow(fract(t), amt);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment