diff --git a/weird/voronoi_growth.frag b/weird/voronoi_growth.frag new file mode 100644 index 0000000..4371f1f --- /dev/null +++ b/weird/voronoi_growth.frag @@ -0,0 +1,57 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform float u_time; + +const mat2 myt = mat2(.12121212, .13131313, -.13131313, .12121212); +const vec2 mys = vec2(1e4, 1e6); + +vec2 rhash(vec2 uv) { + uv *= myt; + uv *= mys; + return fract(fract(uv / mys) * uv); +} + +vec3 hash(vec3 p) { + return fract(sin(vec3(dot(p, vec3(1.0, 57.0, 113.0)), + dot(p, vec3(57.0, 113.0, 1.0)), + dot(p, vec3(1.0, 112.0, 57.0)))) * + 43758.5453); +} + +vec3 voronoi3d(const in vec3 x) { + vec3 p = floor(x); + vec3 f = fract(x); + + float id = 0.0; + vec2 res = vec2(100.0); + for (int k = -1; k <= 1; k++) { + for (int j = -1; j <= 1; j++) { + for (int i = -1; i <= 1; i++) { + vec3 b = vec3(float(i), float(j), float(k)); + vec3 r = vec3(b) - f + hash(p + b); + float d = dot(r, r); + + if (d < res.x) { + id = dot(p + b, vec3(1.0, 57.0, 113.0)); + res = vec2(d, res.x); + } else if (d < res.y) { + res.y = d; + } + } + } + } + + return vec3(sqrt(res), id); +} + +void main() { + vec2 st = gl_FragCoord.xy/u_resolution.xy; + st*=30.; + st.x *= u_resolution.x/u_resolution.y; + gl_FragColor.rgb = voronoi3d(vec3(st, -14.2*(abs(cos(u_time*0.1))+0.01))); + gl_FragColor.r = (st.x)/66.+(st.y)/66.; + gl_FragColor.a = 1.0; +} \ No newline at end of file