Last active
December 28, 2015 10:59
-
-
Save jimfleming/7490103 to your computer and use it in GitHub Desktop.
Moving blobs used as interpolation values between two images.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define INTENSITY 6.5 | |
float blob(vec2 uv, vec2 speed, float time) { | |
// Compute a moving point | |
vec2 point = vec2( | |
sin(speed.x * time), | |
cos(speed.y * time) | |
); | |
float d = 1.0 / distance(uv, point) / INTENSITY; | |
return clamp(d, 0.0, 1.0); | |
} | |
void main(void) { | |
// We might not need this, it should be provided by the context | |
vec2 uv = -1.0 + 2.0 * (gl_FragCoord.xy / iResolution.xy); | |
uv.y *= iResolution.y/iResolution.x; | |
vec4 fg = texture2D(iChannel0, uv); // Sample blur 1 | |
vec4 bg = texture2D(iChannel1, uv); // Sample blur 2 | |
float d = 0.0; // Compute depth map | |
d += blob(uv, vec2(0.7, 0.2), iGlobalTime); | |
d += blob(uv, vec2(0.2, 0.3), iGlobalTime); | |
d += blob(uv, vec2(0.3, 0.1), iGlobalTime); | |
// Lerp between foreground+background | |
vec4 color = mix(fg, bg, 1.0 - d); | |
// DEBUG: color = vec4(d, d, d, 1.0); | |
gl_FragColor = color; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define INTENSITY 0.1 | |
float blob(vec2 uv, vec2 speed) { | |
vec2 point = vec2( | |
sin(speed.x * iGlobalTime), | |
cos(speed.y * iGlobalTime) | |
); | |
return pow(distance(uv, point), 2.0) * INTENSITY; | |
} | |
void main(void) { | |
// We might not need this, it should be provided by the context | |
vec2 uv = (gl_FragCoord.xy / iResolution.xy) * vec2(1.0, -1.0); | |
vec4 fg = texture2D(iChannel0, uv); // Sample blur 1 | |
vec4 bg = texture2D(iChannel1, uv); // Sample blur 2 | |
float d = 0.0; // Compute depth map | |
d += blob(uv, vec2(1.7, 1.2)); | |
d += blob(uv, vec2(1.2, 1.3)); | |
d += blob(uv, vec2(1.3, 1.1)); | |
d = clamp(d, 0.0, 1.0); | |
// Lerp between foreground+background | |
vec4 color = mix(fg, bg, d); | |
color = vec4(d, d, d, 1.0); | |
gl_FragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment