mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-20 04:15:58 +08:00
Compare commits
24 Commits
a98305fa5f
...
godot-4.2
Author | SHA1 | Date | |
---|---|---|---|
51ee380503 | |||
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']
|
@ -40,106 +40,6 @@ float smoothmax(float a, float b, float t) {
|
|||||||
return mix(b, a, h) + t * h * (1. - h);
|
return mix(b, a, h) + t * h * (1. - h);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector) {
|
|
||||||
return (inverse(model_matrix) * vec4(vector, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector) {
|
|
||||||
return (view_matrix * vec4(vector, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
|
|
||||||
vec3 vector_view = vector_transform_world_to_view(view_matrix, vector);
|
|
||||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
|
||||||
vec3 vector_local = vector_transform_world_to_local(model_matrix, vector);
|
|
||||||
return local_to_tangent_matrix * vector_local;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector) {
|
|
||||||
return (model_matrix * vec4(vector, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector) {
|
|
||||||
vec3 vector_world = vector_transform_local_to_world(model_matrix, vector);
|
|
||||||
return (view_matrix * vec4(vector_world, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
|
|
||||||
vec3 vector_view = vector_transform_local_to_view(model_matrix, view_matrix, vector);
|
|
||||||
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
|
||||||
return local_to_tangent_matrix * vector;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector) {
|
|
||||||
return (inv_view_matrix * vec4(vector, 1.0)).xyz;;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
|
|
||||||
vec3 vector_world = vector_transform_view_to_world(inv_view_matrix, vector);
|
|
||||||
return vector_transform_world_to_local(model_matrix, vector_world);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector) {
|
|
||||||
return (projection_matrix * vec4(vector, 1.0)).xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
|
||||||
vec3 vector_local = vector_transform_view_to_local(inv_view_matrix, model_matrix, vector);
|
|
||||||
return vector_transform_local_to_tangent(normal, binormal, tangent, vector_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector) {
|
|
||||||
return (inv_projection_matrix * vec4(vector, 1.0)).xyz;;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
|
|
||||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
|
||||||
return vector_transform_view_to_local(inv_view_matrix, model_matrix, vector_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector) {
|
|
||||||
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
|
|
||||||
return vector_transform_view_to_world(inv_view_matrix, vector_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_screen_to_tangent(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
|
|
||||||
vec3 vector_local = vector_transform_screen_to_local(inv_projection_matrix, inv_view_matrix, model_matrix, vector);
|
|
||||||
return local_to_tangent_matrix * vector_local;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
|
||||||
return tangent_to_local_matrix * vector;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
|
||||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
|
||||||
return vector_transform_local_to_world(model_matrix, vector_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
|
||||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
|
||||||
return vector_transform_local_to_view(model_matrix, view_matrix, vector_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
|
|
||||||
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
|
|
||||||
vec3 vector_local = tangent_to_local_matrix * vector;
|
|
||||||
return vector_transform_local_to_screen(model_matrix, view_matrix, projection_matrix, vector_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
|
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
|
||||||
vec4 sin_in = sin(input);
|
vec4 sin_in = sin(input);
|
||||||
vec4 sin_in_offset = sin(input + 1.0);
|
vec4 sin_in_offset = sin(input + 1.0);
|
||||||
|
@ -32,11 +32,11 @@ func _get_output_port_type(port: int) -> PortType:
|
|||||||
return PORT_TYPE_VECTOR_3D
|
return PORT_TYPE_VECTOR_3D
|
||||||
|
|
||||||
func _get_property_count() -> int:
|
func _get_property_count() -> int:
|
||||||
return 2
|
return 3
|
||||||
|
|
||||||
func _get_property_default_index(index: int) -> int:
|
func _get_property_default_index(index: int) -> int:
|
||||||
match index:
|
match index:
|
||||||
0:
|
0, 1:
|
||||||
return 0
|
return 0
|
||||||
_:
|
_:
|
||||||
return 1
|
return 1
|
||||||
@ -44,24 +44,29 @@ func _get_property_default_index(index: int) -> int:
|
|||||||
func _get_property_name(index: int) -> String:
|
func _get_property_name(index: int) -> String:
|
||||||
match index:
|
match index:
|
||||||
0:
|
0:
|
||||||
|
return "Vector Type"
|
||||||
|
1:
|
||||||
return "From"
|
return "From"
|
||||||
_:
|
_:
|
||||||
return "To"
|
return "To"
|
||||||
|
|
||||||
func _get_property_options(index: int) -> PackedStringArray:
|
func _get_property_options(index: int) -> PackedStringArray:
|
||||||
return ["Local", "World", "View", "Screen", "Tangent"]
|
match index:
|
||||||
|
0:
|
||||||
|
return ["Positional", "Directional"]
|
||||||
|
_:
|
||||||
|
return ["Local", "World", "View", "Clip", "Tangent"]
|
||||||
|
|
||||||
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
|
||||||
return mode == Shader.MODE_SPATIAL
|
return mode == Shader.MODE_SPATIAL
|
||||||
|
|
||||||
func _get_global_code(mode: Shader.Mode) -> String:
|
|
||||||
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
|
||||||
|
|
||||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||||
var code: String
|
var code: String
|
||||||
var from_coord_space_index: int = get_option_index(0)
|
var vector_type: int = get_option_index(0)
|
||||||
var to_coord_space_index: int = get_option_index(1)
|
var from_coord_space_index: int = get_option_index(1)
|
||||||
|
var to_coord_space_index: int = get_option_index(2)
|
||||||
var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)"
|
var input_vector: String = input_vars[0] if input_vars[0] else "vec3(0.0, 0.0, 0.0)"
|
||||||
|
var w_component: String = "1.0" if vector_type == 0 else "0.0"
|
||||||
|
|
||||||
match from_coord_space_index:
|
match from_coord_space_index:
|
||||||
0:
|
0:
|
||||||
@ -69,59 +74,79 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
|||||||
0:
|
0:
|
||||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||||
1:
|
1:
|
||||||
code = "%s = vector_transform_local_to_world(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
2:
|
2:
|
||||||
code = "%s = vector_transform_local_to_view(MODEL_MATRIX, VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (VIEW_MATRIX * MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
3:
|
3:
|
||||||
code = "%s = vector_transform_local_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
4:
|
4:
|
||||||
code = "%s = vector_transform_local_to_tangent(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code = """
|
||||||
|
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||||
|
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||||
|
"""
|
||||||
|
code += "%s = (local_to_tangent_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
1:
|
1:
|
||||||
match to_coord_space_index:
|
match to_coord_space_index:
|
||||||
0:
|
0:
|
||||||
code = "%s = vector_transform_world_to_local(MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (inverse(MODEL_MATRIX) * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
1:
|
1:
|
||||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||||
2:
|
2:
|
||||||
code = "%s = vector_transform_world_to_view(VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
3:
|
3:
|
||||||
code = "%s = vector_transform_world_to_screen(VIEW_MATRIX, PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s =(PROJECTION_MATRIX * VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
4:
|
4:
|
||||||
code = "%s = vector_transform_world_to_tangent(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code = """
|
||||||
|
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||||
|
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||||
|
"""
|
||||||
|
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
2:
|
2:
|
||||||
match to_coord_space_index:
|
match to_coord_space_index:
|
||||||
0:
|
0:
|
||||||
code = "%s = vector_transform_view_to_local(INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
1:
|
1:
|
||||||
code = "%s = vector_transform_view_to_world(INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
2:
|
2:
|
||||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||||
3:
|
3:
|
||||||
code = "%s = vector_transform_view_to_screen(PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
4:
|
4:
|
||||||
code = "%s = vector_transform_view_to_tangent(INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code = """
|
||||||
|
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||||
|
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||||
|
"""
|
||||||
|
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
3:
|
3:
|
||||||
match to_coord_space_index:
|
match to_coord_space_index:
|
||||||
0:
|
0:
|
||||||
code = "%s = vector_transform_screen_to_local(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
1:
|
1:
|
||||||
code = "%s = vector_transform_screen_to_world(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
2:
|
2:
|
||||||
code = "%s = vector_transform_screen_to_view(INV_PROJECTION_MATRIX, %s);" % [output_vars[0], input_vector]
|
code = "%s = (INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
3:
|
3:
|
||||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||||
4:
|
4:
|
||||||
code = "%s = vector_transform_screen_to_tangent(INV_PROJECTION_MATRIX, INV_VIEW_MATRIX, MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code = """
|
||||||
|
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||||
|
mat4 local_to_tangent_mat = mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0));
|
||||||
|
"""
|
||||||
|
code += "%s = (local_to_tangent_mat * inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
4:
|
4:
|
||||||
|
code = """
|
||||||
|
vec3 normal = (inverse(MODEL_MATRIX) * INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz;
|
||||||
|
mat4 tangent_to_local_mat = inverse(mat4(vec4(TANGENT, 1.0), vec4(BINORMAL, 1.0), vec4(normal, 1.0), vec4(0.0, 0.0, 0.0, 1.0)));
|
||||||
|
"""
|
||||||
match to_coord_space_index:
|
match to_coord_space_index:
|
||||||
0:
|
0:
|
||||||
code = "%s = vector_transform_tangent_to_local(NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code += "%s = (tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
1:
|
1:
|
||||||
code = "%s = vector_transform_tangent_to_world(MODEL_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code += "%s = (MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
2:
|
2:
|
||||||
code = "%s = vector_transform_tangent_to_view(MODEL_MATRIX, VIEW_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code += "%s = (VIEW_MATRIX * MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
3:
|
3:
|
||||||
code = "%s = vector_transform_tangent_to_screen(MODEL_MATRIX, VIEW_MATRIX, PROJECTION_MATRIX, NORMAL, BINORMAL, TANGENT, %s);" % [output_vars[0], input_vector]
|
code += "%s = (PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * tangent_to_local_mat * vec4(%s, %s)).xyz;" % [output_vars[0], input_vector, w_component]
|
||||||
4:
|
4:
|
||||||
code = "%s = %s;" % [output_vars[0], input_vector]
|
code = "%s = %s;" % [output_vars[0], input_vector]
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -10,6 +10,7 @@ Returns the transformed vector of the input value <i><b>in</b></i> from one coor
|
|||||||
**Controls**
|
**Controls**
|
||||||
|Name|Options|Description|
|
|Name|Options|Description|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
|Vector type|Positional, Directional|Positional will take into account translation data, Directional won't|
|
||||||
|From|Local, World, View, Screen, Tangent|Coordinate space from which you want to transform the input vector|
|
|From|Local, World, View, Screen, Tangent|Coordinate space from which you want to transform the input vector|
|
||||||
|To|Local, World, View, Screen, Tangent|Coordinate space to which you want to transform the input vector|
|
|To|Local, World, View, Screen, Tangent|Coordinate space to which you want to transform the input vector|
|
||||||
|
|
||||||
|
@ -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