Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Last active August 8, 2020 21:43
Show Gist options
  • Save CharStiles/4e8dbd8da59e044fa7a0f3f55e746e1e to your computer and use it in GitHub Desktop.
Save CharStiles/4e8dbd8da59e044fa7a0f3f55e746e1e to your computer and use it in GitHub Desktop.
#version 150
// I made this using kodelife if you modify the inputs and outputs correctly it should translate to other programs as well
// things to look out for is all the uniforms, the input pixel position and the output pixel color
uniform float time;
uniform vec2 resolution;
uniform sampler2D prevPass;
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
#define PI 3.1415
vec4 cosPal(float t){
vec3 brightness = vec3(0.4);
vec3 contrast = vec3(0.2);
vec3 osc = vec3(0.3,0.32,0.2);
vec3 phase = vec3(0.3,0.3,0.3);
// vec3 brightness = vec3(0.5);
// vec3 contrast = vec3(0.2);
// vec3 osc = vec3(1.0, 1.0, 1.0);
// vec3 phase = vec3(0.020, 0.20, 0.10);
vec3 ret = brightness + contrast * (cos(((osc*t) + phase)*2.*PI));
return vec4(ret,1);
}
float pModPolar(inout 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;
// For an odd number of repetitions, fix cell index of the cell in -x direction
// (cell index would be e.g. -5 and 5 in the two halves of the cell):
if (abs(c) >= (repetitions/2)) c = abs(c);
return c;
}
void main(void)
{
vec2 uv = -1. + 2. * inData.v_texcoord;
uv.x *= resolution.x/resolution.y;
uv *= 2; // make everything smaller
pModPolar(uv,(sin(time/21.) + 3)*1.);
uv.x -= 01.9 + time/20.;
// c can be whatever you want that is not standard. c is usually like a
// const number like vec2(1) to make it mod every 1 unit in the x and y direction
vec2 modSpace = vec2(2.4)+ vec2((sin(time/20.)*0.93),tan(time/2.));
// this is your standard mod space in 2 dimentions formula
uv = mod(uv,modSpace) - (modSpace*0.5);
// these make for a outline to the circle. you cant see it atm but thats what it was originally
float inner = .50 - (length(uv)+0.010);
float outter = .90 - (length(uv)-0.001);
// control those varibles
outter = clamp(outter,0,1.);
outter = ceil(outter);
inner = clamp(inner,0,5.);
// inner = ceil(inner);
// now the angle is the degree the pixel is at if it was on a cartesian plane
float angle = (atan((uv.x/uv.y))/5.);
if(uv.y < 0 ){
angle += 22133.0; // i forgot why i did this. i think i was trying to make it look continuous
}
// good ol cos palette
vec4 outerColor = cosPal(angle + time/2) * outter;
vec4 innerColor = cosPal( time/2);
// this is like a paint mixer you mix the first two inputs with variying the amount of each using the
// third varible
vec4 ret = mix(outerColor,innerColor,inner);
// get the previous buffer but offput it by a small number so it looks cooler (you get trailing effect)
vec4 prev = texture2D(prevFrame, inData.v_texcoord + sin(uv.x*02)*0.01 );
// the *0.98 makes those trails fade to black. i forgot why i ret*ret maybe it just looks better that way
ret = mix(prev * 00.98, ret,ret* ret);
fragColor = ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment