// voronoi distance noise, based on iq's articles float Voronoi(float2 x) { float2 p = floor(x); float2 f = frac(x); float2 res = float2(8, 8); for(int j = -1; j <= 1; j ++) { for(int i = -1; i <= 1; i ++) { float2 b = float2(i, j); float2 r = b - f + Rand2(p + b); // chebyshev distance, one of many ways to do this float d = max(abs(r.x), abs(r.y)); if(d < res.x) { res.y = res.x; res.x = d; } else if(d < res.y) { res.y = d; } } } return res.y - res.x; }