mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-08 10:23:24 +08:00
Update Voronoi.gdshaderinc
This commit is contained in:
parent
55039f4c6b
commit
41f016feca
@ -1,22 +1,11 @@
|
|||||||
|
#include "res://addons/ShaderLib/Maths/Vector/Distance/Manhattan2D.gdshaderinc"
|
||||||
|
#include "res://addons/ShaderLib/Maths/Vector/Distance/Chebyshev2D.gdshaderinc"
|
||||||
|
|
||||||
vec2 voronoi_random_vector(vec2 p) {
|
vec2 voronoi_random_vector(vec2 p) {
|
||||||
mat2 matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98));
|
mat2 matrix = mat2(vec2(15.27, 47.63), vec2(99.41, 89.98));
|
||||||
return fract(sin(p * matrix) * 46839.32);
|
return fract(sin(p * matrix) * 46839.32);
|
||||||
}
|
}
|
||||||
|
|
||||||
float voronoi_euclidean_distance(vec2 point1, vec2 point2){
|
|
||||||
return distance(point1, point2);
|
|
||||||
}
|
|
||||||
|
|
||||||
float voronoi_manhattan_distance(vec2 point1, vec2 point2) {
|
|
||||||
vec2 d = point1 - point2;
|
|
||||||
return abs(d.x) + abs(d.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
float voronoi_chebyshev_distance(vec2 point1, vec2 point2, float power) {
|
|
||||||
vec2 p = point1 - point2;
|
|
||||||
return pow(pow(p.x, power) + pow(p.y, power), 1. / power);
|
|
||||||
}
|
|
||||||
|
|
||||||
void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells){
|
void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells){
|
||||||
vec2 grid_uv = fract(uv * cell_density);
|
vec2 grid_uv = fract(uv * cell_density);
|
||||||
vec2 grid_id = floor(uv * cell_density);
|
vec2 grid_id = floor(uv * cell_density);
|
||||||
@ -32,13 +21,13 @@ void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance
|
|||||||
|
|
||||||
switch(distance_index){
|
switch(distance_index){
|
||||||
case 1:
|
case 1:
|
||||||
d = voronoi_manhattan_distance(grid_uv, p);
|
d = manhattan_distance_2d(grid_uv, p);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
d = voronoi_chebyshev_distance(grid_uv, p, chebyshev_power);
|
d = chebyshev_distance_2d(grid_uv, p, chebyshev_power);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
d = voronoi_euclidean_distance(grid_uv, p);
|
d = distance(grid_uv, p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user