Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created March 8, 2018 13:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save keijiro/be1975d8c92d1f07fbbbce3164cbdfaf to your computer and use it in GitHub Desktop.
Save keijiro/be1975d8c92d1f07fbbbce3164cbdfaf to your computer and use it in GitHub Desktop.
KodeLife fragment shader sketch
#version 150
uniform float time;
uniform sampler2D prevFrame;
uniform vec2 resolution;
uniform vec3 spectrum;
out vec4 fragColor;
float rand(float x, float y)
{
return fract(sin(12.9898 * x + 78.233 * y) * 43758.5453);
}
void main(void)
{
vec2 uv = gl_FragCoord.xy / resolution;
float aspect = resolution.x / resolution.y;
float bt = floor(time * 2);
// polar coordinates
vec2 p = (uv - 0.5) * vec2(aspect, 1);
p = vec2(atan(p.y, p.x), length(p));
// burst
float b1 = sin(p.x * 30 * rand(0, time) + time * 11.23);
float b2 = sin(p.x * 10 * rand(1, time) + time * 10.74);
float c = 1 - step((1 + b1 * b2 / 2) * spectrum.x, p.y);
// sliding rims
float dx = rand(floor(p.y * 14), bt) - 0.5;
p.x += p.y * dx * 0.2;
p.y *= 0.995;
// bring back to screen coordinates
p = vec2(cos(p.x), sin(p.x)) * p.y;
uv = p * vec2(1 / aspect, 1) + 0.5;
// feedback
c += texture(prevFrame, uv).r * 0.985;
// color gradient
float c1 = 0.5 + sin(c * 9.12 + time * 1.11) * 0.5;
float c2 = 0.5 + sin(c * 6.33 + time * 1.73) * 0.5;
fragColor = vec4(1, c1, c2, 0) * c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment