1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-10 11:09:35 +08:00

24 lines
733 B
Plaintext
Raw Normal View History

2023-10-12 19:46:55 +05:30
void voronoi_noise(vec2 uv, float cell_density, float angle_offset, out float output, out float cells){
2023-10-13 15:49:48 +05:30
vec2 _g = floor(uv * cell_density);
vec2 _f = fract(uv * cell_density);
vec3 _res = vec3(8.0, 0.0, 0.0);
mat2 _matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98));
2023-10-12 19:46:55 +05:30
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
vec2 lattice = vec2(float(x), float(y));
2023-10-13 15:49:48 +05:30
vec2 new_uv = lattice + _g;
new_uv = fract(sin(new_uv * _matrix) * 46839.32);
2023-10-12 19:46:55 +05:30
vec2 offset = vec2(sin(new_uv.y * angle_offset) * 0.5 + 0.5, cos(new_uv.x * angle_offset) * 0.5 + 0.5);
2023-10-13 15:49:48 +05:30
float d = distance(lattice + offset, _f);
if(d < _res.x)
2023-10-12 19:46:55 +05:30
{
2023-10-13 15:49:48 +05:30
_res = vec3(d, offset.x, offset.y);
output = _res.x;
cells = _res.y;
2023-10-12 19:46:55 +05:30
}
}
}
}