2023-10-12 19:46:55 +05:30
|
|
|
@tool
|
2024-09-28 00:45:16 +05:30
|
|
|
class_name VisualShaderNodeProceduralVoronoi extends ShaderLib
|
2023-10-12 19:46:55 +05:30
|
|
|
|
|
|
|
func _get_name() -> String:
|
|
|
|
return "Voronoi"
|
|
|
|
|
|
|
|
func _get_category() -> String:
|
|
|
|
return "Procedural/Noise"
|
|
|
|
|
|
|
|
func _get_description() -> String:
|
|
|
|
return "Generates a Voronoi or Worley noise based on input UV."
|
|
|
|
|
|
|
|
func _get_return_icon_type() -> VisualShaderNode.PortType:
|
|
|
|
return PORT_TYPE_SCALAR
|
|
|
|
|
|
|
|
func _get_input_port_count() -> int:
|
2024-03-19 13:03:56 +05:30
|
|
|
var distance_index: int = get_option_index(0)
|
|
|
|
match distance_index:
|
|
|
|
2:
|
|
|
|
return 4
|
|
|
|
_:
|
|
|
|
return 3
|
2023-10-12 19:46:55 +05:30
|
|
|
|
|
|
|
func _get_input_port_name(port: int) -> String:
|
2024-03-19 13:03:56 +05:30
|
|
|
var distance_index: int = get_option_index(0)
|
|
|
|
match distance_index:
|
2023-10-12 19:46:55 +05:30
|
|
|
2:
|
2024-03-19 13:03:56 +05:30
|
|
|
match port:
|
|
|
|
0:
|
|
|
|
return "uv"
|
|
|
|
1:
|
|
|
|
return "cell density"
|
|
|
|
2:
|
|
|
|
return "angle offset"
|
|
|
|
_:
|
|
|
|
return "chebyshev power"
|
|
|
|
_:
|
|
|
|
match port:
|
|
|
|
0:
|
|
|
|
return "uv"
|
|
|
|
1:
|
|
|
|
return "cell density"
|
|
|
|
_:
|
|
|
|
return "angle offset"
|
2023-10-12 19:46:55 +05:30
|
|
|
|
|
|
|
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
|
|
|
|
match port:
|
|
|
|
0:
|
|
|
|
return PORT_TYPE_VECTOR_2D
|
2024-03-19 13:03:56 +05:30
|
|
|
_:
|
2023-10-12 19:46:55 +05:30
|
|
|
return PORT_TYPE_SCALAR
|
|
|
|
|
2024-01-12 16:53:06 +05:30
|
|
|
func _get_input_port_default_value(port: int) -> Variant:
|
2024-03-19 13:03:56 +05:30
|
|
|
var distance_index: int = get_option_index(0)
|
|
|
|
match distance_index:
|
2024-01-12 16:53:06 +05:30
|
|
|
2:
|
2024-03-19 13:03:56 +05:30
|
|
|
match port:
|
|
|
|
1:
|
|
|
|
return 5.0
|
|
|
|
2:
|
|
|
|
return 2.0
|
|
|
|
3:
|
2024-09-29 23:42:44 +05:30
|
|
|
return 5.0
|
2024-03-19 13:03:56 +05:30
|
|
|
_:
|
|
|
|
return null
|
2024-01-12 16:53:06 +05:30
|
|
|
_:
|
2024-03-19 13:03:56 +05:30
|
|
|
match port:
|
|
|
|
1:
|
|
|
|
return 5.0
|
|
|
|
2:
|
|
|
|
return 2.0
|
|
|
|
_:
|
|
|
|
return null
|
2024-01-12 16:53:06 +05:30
|
|
|
|
2023-10-12 19:46:55 +05:30
|
|
|
func _get_output_port_count() -> int:
|
|
|
|
return 2
|
|
|
|
|
|
|
|
func _get_output_port_name(port: int) -> String:
|
|
|
|
match port:
|
|
|
|
0:
|
|
|
|
return "output"
|
2024-03-19 13:03:56 +05:30
|
|
|
_:
|
2023-10-12 19:46:55 +05:30
|
|
|
return "cells"
|
|
|
|
|
|
|
|
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
|
|
|
|
return PORT_TYPE_SCALAR
|
|
|
|
|
2024-03-19 13:03:56 +05:30
|
|
|
func _get_property_count() -> int:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
func _get_property_name(index: int) -> String:
|
|
|
|
return "Distance"
|
|
|
|
|
|
|
|
func _get_property_default_index(index: int) -> int:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
func _get_property_options(index: int) -> PackedStringArray:
|
|
|
|
return ["Euclidean", "Manhattan", "Chebyshev"]
|
|
|
|
|
2023-10-12 19:46:55 +05:30
|
|
|
func _get_global_code(mode: Shader.Mode) -> String:
|
2024-09-28 00:45:16 +05:30
|
|
|
return "#include \"res://addons/ShaderLib_%s/Procedural/Procedural.gdshaderinc\"" % [version]
|
2023-10-12 19:46:55 +05:30
|
|
|
|
|
|
|
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
|
|
|
var uv: String = "UV"
|
|
|
|
|
|
|
|
if input_vars[0]:
|
|
|
|
uv = input_vars[0]
|
|
|
|
|
2024-03-19 13:03:56 +05:30
|
|
|
var distance_index: int = get_option_index(0)
|
|
|
|
|
2023-10-12 19:46:55 +05:30
|
|
|
var cell_density: String = input_vars[1]
|
|
|
|
var angle_offset: String = input_vars[2]
|
2024-03-19 13:03:56 +05:30
|
|
|
|
2023-10-12 19:46:55 +05:30
|
|
|
var output: String = output_vars[0]
|
|
|
|
var cells: String = output_vars[1]
|
|
|
|
|
2024-09-29 23:42:44 +05:30
|
|
|
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]
|