mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-20 04:15:58 +08:00
Compare commits
23 Commits
a98305fa5f
...
main
Author | SHA1 | Date | |
---|---|---|---|
c1c786f345 | |||
afae2c766e | |||
85fc207dc0 | |||
1b66431979 | |||
506c677307 | |||
8bac036b66 | |||
009b94277f | |||
e0cd7320e7 | |||
6576785b47 | |||
217bf0a24e | |||
4844686953 | |||
8e9910a8d3 | |||
a4640eed2f | |||
5cc50c533f | |||
571098f3d9 | |||
fae913cea6 | |||
9d7c679c5b | |||
67ec588347 | |||
63acf5d341 | |||
8972c2da37 | |||
5ece7a3bd3 | |||
3fc8d868a6 | |||
32c40f1371 |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: DigvijaysinhGohil
|
||||||
|
patreon: DigvijaysinhG
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@ -1,9 +1,6 @@
|
|||||||
@tool
|
@tool
|
||||||
class_name VisualShaderNodeProceduralVoronoi extends ShaderLib
|
class_name VisualShaderNodeProceduralVoronoi extends ShaderLib
|
||||||
|
|
||||||
func _init() -> void:
|
|
||||||
output_port_for_preview = 0
|
|
||||||
|
|
||||||
func _get_name() -> String:
|
func _get_name() -> String:
|
||||||
return "Voronoi"
|
return "Voronoi"
|
||||||
|
|
||||||
@ -63,7 +60,7 @@ func _get_input_port_default_value(port: int) -> Variant:
|
|||||||
2:
|
2:
|
||||||
return 2.0
|
return 2.0
|
||||||
3:
|
3:
|
||||||
return 2.0
|
return 5.0
|
||||||
_:
|
_:
|
||||||
return null
|
return null
|
||||||
_:
|
_:
|
||||||
@ -113,13 +110,15 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
|||||||
|
|
||||||
var cell_density: String = input_vars[1]
|
var cell_density: String = input_vars[1]
|
||||||
var angle_offset: String = input_vars[2]
|
var angle_offset: String = input_vars[2]
|
||||||
var chebyshev_power: String = "0."
|
|
||||||
|
|
||||||
if distance_index == 2:
|
|
||||||
if input_vars[3]:
|
|
||||||
chebyshev_power = input_vars[3]
|
|
||||||
|
|
||||||
var output: String = output_vars[0]
|
var output: String = output_vars[0]
|
||||||
var cells: String = output_vars[1]
|
var cells: String = output_vars[1]
|
||||||
|
|
||||||
return "voronoi_noise(%s, %s, %s, %s, %s, %s, %s);" % [uv, cell_density, angle_offset, distance_index, chebyshev_power, output, cells]
|
match distance_index:
|
||||||
|
1:
|
||||||
|
return "%s = voronoi_noise_manhattan(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells]
|
||||||
|
2:
|
||||||
|
var chebyshev_power: String = input_vars[3]
|
||||||
|
return "%s = voronoi_noise_chebyshev(%s, %s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, chebyshev_power, cells]
|
||||||
|
_:
|
||||||
|
return "%s = voronoi_noise_euclidean(%s, %s, %s, %s);" % [output, uv, cell_density, angle_offset, cells]
|
||||||
|
@ -130,7 +130,7 @@ vec2 voronoi_random_vector(vec2 p) {
|
|||||||
return fract(sin(p * matrix) * 46839.32);
|
return fract(sin(p * matrix) * 46839.32);
|
||||||
}
|
}
|
||||||
|
|
||||||
void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells){
|
float voronoi_noise_euclidean(vec2 uv, float cell_density, float angle_offset, 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);
|
||||||
vec2 cell_id = vec2(0);
|
vec2 cell_id = vec2(0);
|
||||||
@ -142,18 +142,31 @@ void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance
|
|||||||
vec2 n = voronoi_random_vector(grid_id + offset);
|
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||||
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||||
float d = min_dist;
|
float d = min_dist;
|
||||||
|
d = distance(grid_uv, p);
|
||||||
switch(distance_index){
|
if(d < min_dist) {
|
||||||
case 1:
|
min_dist = d;
|
||||||
d = manhattan_distance_2d(grid_uv, p);
|
cell_id = voronoi_random_vector(grid_id + offset);
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
d = chebyshev_distance_2d(grid_uv, p, chebyshev_power);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
d = distance(grid_uv, p);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cells = cell_id.y;
|
||||||
|
return min_dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
float voronoi_noise_manhattan(vec2 uv, float cell_density, float angle_offset, out float cells){
|
||||||
|
vec2 grid_uv = fract(uv * cell_density);
|
||||||
|
vec2 grid_id = floor(uv * cell_density);
|
||||||
|
vec2 cell_id = vec2(0);
|
||||||
|
float min_dist = 100.;
|
||||||
|
|
||||||
|
for(float y = -1.; y <= 1.; y++) {
|
||||||
|
for(float x = -1.; x <= 1.; x++) {
|
||||||
|
vec2 offset = vec2(x, y);
|
||||||
|
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||||
|
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||||
|
float d = min_dist;
|
||||||
|
d = manhattan_distance_2d(grid_uv, p);
|
||||||
|
|
||||||
if(d < min_dist) {
|
if(d < min_dist) {
|
||||||
min_dist = d;
|
min_dist = d;
|
||||||
@ -162,8 +175,33 @@ void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output = min_dist;
|
|
||||||
cells = cell_id.y;
|
cells = cell_id.y;
|
||||||
|
return min_dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
float voronoi_noise_chebyshev(vec2 uv, float cell_density, float angle_offset, float chebyshev_power, out float cells){
|
||||||
|
vec2 grid_uv = fract(uv * cell_density);
|
||||||
|
vec2 grid_id = floor(uv * cell_density);
|
||||||
|
vec2 cell_id = vec2(0);
|
||||||
|
float min_dist = 100.;
|
||||||
|
|
||||||
|
for(float y = -1.; y <= 1.; y++) {
|
||||||
|
for(float x = -1.; x <= 1.; x++) {
|
||||||
|
vec2 offset = vec2(x, y);
|
||||||
|
vec2 n = voronoi_random_vector(grid_id + offset);
|
||||||
|
vec2 p = offset + vec2(sin(n.x + angle_offset) * .5 + .5, cos(n.y + angle_offset) * .5 + .5);
|
||||||
|
float d = min_dist;
|
||||||
|
d = chebyshev_distance_2d(grid_uv, p, chebyshev_power);
|
||||||
|
|
||||||
|
if(d < min_dist) {
|
||||||
|
min_dist = d;
|
||||||
|
cell_id = voronoi_random_vector(grid_id + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cells = cell_id.y;
|
||||||
|
return min_dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ellipse_shape(vec2 uv, float width, float height) {
|
float ellipse_shape(vec2 uv, float width, float height) {
|
||||||
|
@ -25,7 +25,9 @@ Generates a Voronoi or Worley noise based on input UV. Voronoi noise is generate
|
|||||||
<br>`res://addons/ShaderLib/Procedural/Procedural.gdshaderinc`
|
<br>`res://addons/ShaderLib/Procedural/Procedural.gdshaderinc`
|
||||||
|
|
||||||
**Method signature**
|
**Method signature**
|
||||||
<br>`void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance_index, float chebyshev_power, out float output, out float cells)`
|
<br>`float voronoi_noise_euclidean(vec2 uv, float cell_density, float angle_offset, out float cells)`
|
||||||
|
<br>`float voronoi_noise_manhattan(vec2 uv, float cell_density, float angle_offset, out float cells)`
|
||||||
|
<br>`float voronoi_noise_chebyshev(vec2 uv, float cell_density, float angle_offset, float chebyshev_power, out float cells)`
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|Name|Type|Description|
|
|Name|Type|Description|
|
||||||
@ -33,8 +35,6 @@ Generates a Voronoi or Worley noise based on input UV. Voronoi noise is generate
|
|||||||
|uv|vec2|Input UV value|
|
|uv|vec2|Input UV value|
|
||||||
|cell_density|float|Density of generated cells|
|
|cell_density|float|Density of generated cells|
|
||||||
|angle_offset|float|Offset values for points|
|
|angle_offset|float|Offset values for points|
|
||||||
|distance_index|int|Distance matrix to use for Voronoi, 0 = Euclidean, 1 = Manhattan, 2 = Chebyshev|
|
|
||||||
|chebyshev_power|float|Power for Chebyshev distance|
|
|chebyshev_power|float|Power for Chebyshev distance|
|
||||||
|output|out float|Output noise value|
|
|
||||||
|cells|out float|Output raw cell data|
|
|cells|out float|Output raw cell data|
|
||||||
___
|
___
|
Reference in New Issue
Block a user