Skip to content

Instantly share code, notes, and snippets.

@gre
Forked from gre/TEMPLATE.glsl
Last active January 4, 2016 10:29
Show Gist options
  • Save gre/8608978 to your computer and use it in GitHub Desktop.
Save gre/8608978 to your computer and use it in GitHub Desktop.
#ifdef GL_ES
precision highp float;
#endif
#define QUALITY 32
// General parameters
uniform sampler2D from;
uniform sampler2D to;
uniform float progress;
uniform vec2 resolution;
// Custom parameters
uniform float size;
const float GOLDEN_ANGLE = 2.399963229728653; // PI * (3.0 - sqrt(5.0))
vec4 blur(sampler2D t, vec2 c, float radius) {
vec4 sum = vec4(0.0);
float q = float(QUALITY);
// Using a "spiral" to propagate points.
for (int i=0; i<QUALITY; ++i) {
float fi = float(i);
float a = fi * GOLDEN_ANGLE;
float r = sqrt(fi / q) * radius;
vec2 p = c + r * vec2(cos(a), sin(a));
sum += texture2D(t, p);
}
return sum / q;
}
void main()
{
vec2 p = gl_FragCoord.xy / resolution.xy;
float inv = 1.-progress;
gl_FragColor = inv*blur(from, p, progress*size) + progress*blur(to, p, inv*size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment