Back to shaders
Shader test bench
Electric Voronoi Cells
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
precision mediump float;
uniform vec2 resolution;
uniform float time;
vec2 hash(vec2 p) { p = vec2(dot(p, vec2(127.1,311.7)), dot(p, vec2(269.5,183.3))); return fract(sin(p) * 43758.5453); }
void main() {
vec2 uv = gl_FragCoord.xy / resolution.xy;
uv.x *= resolution.x / resolution.y;
vec2 g = uv * 7.0;
vec2 id = floor(g);
vec2 f = fract(g);
float d1 = 9.0;
float d2 = 9.0;
for (int y=-1; y<=1; y++) for (int x=-1; x<=1; x++) {
vec2 o = vec2(float(x), float(y));
vec2 r = hash(id + o);
r = 0.5 + 0.42 * sin(time + 6.28318 * r);
float d = length(o + r - f);
if (d < d1) { d2 = d1; d1 = d; } else if (d < d2) d2 = d;
}
float edge = smoothstep(0.035, 0.0, d2 - d1);
vec3 base = mix(vec3(0.02,0.04,0.12), vec3(0.04,0.5,0.85), d1);
gl_FragColor = vec4(base + edge * vec3(0.7, 0.95, 1.0), 1.0);
}