Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Last active September 2, 2024 10:13
Show Gist options
  • Save tshirtman/d952326d2be9acc88f73441322e2558b to your computer and use it in GitHub Desktop.
Save tshirtman/d952326d2be9acc88f73441322e2558b to your computer and use it in GitHub Desktop.
glsl vjaying experiment
$HEADER$
float PI = 3.1415926535;
uniform vec2 resolution;
uniform float time;
vec2 rotate(vec2 pos, float angle, vec2 center){
pos -= center;
pos *= mat2(cos(angle), sin(-angle), sin(angle), cos(angle));
pos += center;
return pos;
}
vec2 scale(vec2 pos, float scale, vec2 center){
pos -= center;
pos *= scale;
pos += center;
return pos;
}
float nsin(float f){
return .5 + .5 * sin(f);
}
float ncos(float f){
return .5 + .5 * cos(f);
}
vec3 f1(vec2 pos, float time) {
vec2 center = scale(vec2(nsin(time), ncos(time)), .5, vec2(.5));
vec3 c = vec3(1.0);
float d = distance(pos, center);
c *= step(.9, 1. - d);
return c;
}
vec3 ab(vec2 pos, float time){
vec2 offset_ = vec2(2. / resolution.x, 0.);
return vec3(
f1(pos - offset_, time) * vec3(2.0, 1.0, 0.0) +
f1(pos, time) * vec3(1.0, 1.0, 1.0) +
f1(pos + offset_, time) * vec3(0.0, 1.0, 2.0)
) / 3.0;
}
vec3 blur(vec2 pos, float time){
vec3 c = vec3(0., 0., 0.);
float steps = 5.0;
for (float t=0.0; t <= steps; t += 1.0){
c += ab(pos, time+t/100.);
}
return c/ steps;
}
void main(void)
{
vec2 pos = gl_FragCoord.xy / resolution;
vec3 c = blur(pos, time);
gl_FragColor = vec4(
c.r,
c.g,
c.b,
1.0
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment