lygia
/v1.1.6
/generative
/voronoi
)Voronoi positions and distance to centroids
Dependencies:
Use:
<vec3> voronoi(<vec2> pos, <float> time)
#ifndef VORONOI_RANDOM_FNC
#define VORONOI_RANDOM_FNC(UV) ( 0.5 + 0.5 * sin(time + TAU * random2(UV) ) );
#endif
#ifndef FNC_VORONOI
#define FNC_VORONOI
vec3 voronoi(vec2 uv, float time) {
vec2 i_uv = floor(uv);
vec2 f_uv = fract(uv);
vec3 rta = vec3(0.0, 0.0, 10.0);
for (int j=-1; j<=1; j++ ) {
for (int i=-1; i<=1; i++ ) {
vec2 neighbor = vec2(float(i),float(j));
vec2 point = VORONOI_RANDOM_FNC(i_uv + neighbor);
point = 0.5 + 0.5 * sin(time + TAU * point);
vec2 diff = neighbor + point - f_uv;
float dist = length(diff);
if ( dist < rta.z ) {
rta.xy = point;
rta.z = dist;
}
}
}
return rta;
}
vec3 voronoi(vec2 p) { return voronoi(p, 0.0); }
vec3 voronoi(vec3 p) { return voronoi(p.xy, p.z); }
#endif
Dependencies:
Use:
<float3> voronoi(<float2> pos, <float> time)
#ifndef VORONOI_RANDOM_FNC
#define VORONOI_RANDOM_FNC(UV) ( 0.5 + 0.5 * sin(time + TAU * random2(UV) ) );
#endif
#ifndef FNC_VORONOI
#define FNC_VORONOI
float3 voronoi(float2 uv, float time) {
float2 i_uv = floor(uv);
float2 f_uv = frac(uv);
float3 rta = float3(0.0, 0.0, 10.0);
for (int j=-1; j<=1; j++ ) {
for (int i=-1; i<=1; i++ ) {
float2 neighbor = float2(float(i),float(j));
float2 p = VORONOI_RANDOM_FNC(i_uv + neighbor);
p = 0.5 + 0.5 * sin(time + TAU * p);
float2 diff = neighbor + p - f_uv;
float dist = length(diff);
if ( dist < rta.z ) {
rta.xy = p;
rta.z = dist;
}
}
}
return rta;
}
float3 voronoi(float2 p) { return voronoi(p, 0.0); }
float3 voronoi(float3 p) { return voronoi(p.xy, p.z); }
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository