-
-
Save elkozmon/b484311b68a68867523af419dd225800 to your computer and use it in GitHub Desktop.
simple metaball shader
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
precision highp float; | |
uniform float time; | |
uniform vec2 mouse; | |
uniform vec2 resolution; | |
float ball(vec2 p, float fx, float fy, float ax, float ay) { | |
vec2 r = vec2(p.x + sin(time * fx) * ax, p.y + cos(time * fy) * ay); | |
return 0.05 / length(r); | |
} | |
void main(void) { | |
vec2 q = gl_FragCoord.xy / resolution.xy; | |
vec2 p = -1.0 + 2.0 * q; | |
p.x *= resolution.x / resolution.y; | |
float col = 0.0; | |
col += ball(p, 1.0, 2.0, 0.1, 0.2); | |
col += ball(p, 1.5, 2.5, 0.2, 0.3); | |
col += ball(p, 2.0, 3.0, 0.3, 0.4); | |
col += ball(p, 2.5, 3.5, 0.4, 0.5); | |
col += ball(p, 3.0, 4.0, 0.5, 0.6); | |
col += ball(p, 1.5, 0.5, 0.6, 0.7); | |
col += ball(p, 0.1, .5, 0.6, 0.7); | |
col = smoothstep(0.99, 1.0, col); | |
gl_FragColor = vec4(col * 0.8, col * 0.3, col * 0.3, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment