Code based on Inigo Quilez approach:
It uses the same random calculations as the Unity standard Shader Graph Voronoi so both patterns can be overlapped.
Code based on Inigo Quilez approach:
It uses the same random calculations as the Unity standard Shader Graph Voronoi so both patterns can be overlapped.
$precision2 n = floor(UV * CellDensity); | |
$precision2 f = frac(UV * CellDensity); | |
// first pass: regular voronoi | |
$precision2 mg, mr; | |
$precision md = 8.0; | |
for (int j= -1; j <= 1; j++) { | |
for (int i= -1; i <= 1; i++) { | |
$precision2 g = $precision2(i,j); | |
$precision2x2 m = $precision2x2(15.27, 47.63, 99.41, 89.98); | |
$precision2 uvr = frac(sin(mul(g+n, m)) * 46839.32); | |
$precision2 o = $precision2(sin(uvr.y*+AngleOffset)*0.5+0.5, cos(uvr.x*AngleOffset)*0.5+0.5); | |
$precision2 r = g + o - f; | |
$precision d = dot(r,r); | |
if( d<md ) { | |
md = d; | |
mr = r; | |
mg = g; | |
} | |
} | |
} | |
// second pass: distance to borders | |
md = 8.0; | |
for (int j= -2; j <= 2; j++) { | |
for (int i= -2; i <= 2; i++) { | |
$precision2 g = mg + $precision2(i,j); | |
$precision2x2 m = $precision2x2(15.27, 47.63, 99.41, 89.98); | |
$precision2 uvr = frac(sin(mul(g+n, m)) * 46839.32); | |
$precision2 o = $precision2(sin(uvr.y*+AngleOffset)*0.5+0.5, cos(uvr.x*AngleOffset)*0.5+0.5); | |
$precision2 r = g + o - f; | |
if ( dot(mr-r,mr-r)>0.0001 ) { | |
md = min(md, dot( 0.5*(mr+r), normalize(r-mr) )); | |
} | |
} | |
} | |
Out = $precision3(md, mr.x, mr.y); |
This is great! I was looking for a way to do something similar. I wanted to create UVs that I could use to place textures accurately in each cell so I could move textures along with the voronoi noise. This looks really close. How could you modify this to get a nice clean UV map for each cell? This looks more like you are generating this for normals.