Skip to content

Instantly share code, notes, and snippets.

@fand
Created May 8, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/2ebee8524c50d63b1f6d84f177fcd136 to your computer and use it in GitHub Desktop.
Save fand/2ebee8524c50d63b1f6d84f177fcd136 to your computer and use it in GitHub Desktop.
shader sample
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
float metaball (in vec2 position) {
float d = pow(sin(time * 1.4), 3.) * 0.5;
float dist1 = pow(max(1.0 - distance(position, vec2(0.5 + d, 0.5)) * 3.0, 0.0), 2.0);
float dist2 = pow(max(1.0 - distance(position, vec2(0.5 - d, 0.5)) * 3.0, 0.0), 2.0);
float dist3 = pow(max(1.0 - distance(position, vec2(-0.5 + d, 0.5)) * 3.0, 0.0), 2.0);
float dist4 = pow(max(1.0 - distance(position, vec2(-0.5 - d, 0.5)) * 3.0, 0.0), 2.0);
float dist5 = pow(max(1.0 - distance(position, vec2(1.5 + d, 0.5)) * 3.0, 0.0), 2.0);
float dist6 = pow(max(1.0 - distance(position, vec2(1.5 - d, 0.5)) * 3.0, 0.0), 2.0);
return smoothstep(0.1, 0.101, dist1 + dist2 + dist3 + dist4 + dist5 + dist6);
}
void main (void) {
vec2 position = gl_FragCoord.xy / resolution.xy;
vec2 pos = fract(position * 4.);
float r = metaball(pos);
float g = metaball(pos + vec2(sin(time * 3.), cos(time * 4.)) * 0.03);
float b = metaball(pos + vec2(cos(time * 3.), sin(time * 4.)) * 0.03);
gl_FragColor = vec4(r, g, b, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment