2023-10-12 19:46:55 +05:30
|
|
|
@tool
|
|
|
|
class_name VisualShaderNodeProceduralVoronoi extends VisualShaderNodeCustom
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
output_port_for_preview = 0
|
|
|
|
|
|
|
|
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:
|
|
|
|
return 2.0
|
|
|
|
_:
|
|
|
|
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:
|
|
|
|
var code: String = preload("Voronoi.gdshaderinc").code
|
|
|
|
return code
|
|
|
|
|
|
|
|
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
|
|
|
var chebyshev_power: String = "0."
|
|
|
|
|
|
|
|
if distance_index == 2:
|
|
|
|
if input_vars[3]:
|
|
|
|
chebyshev_power = input_vars[3]
|
|
|
|
|
2023-10-12 19:46:55 +05:30
|
|
|
var output: String = output_vars[0]
|
|
|
|
var cells: String = output_vars[1]
|
|
|
|
|
2024-03-19 13:03:56 +05:30
|
|
|
return "voronoi_noise(%s, %s, %s, %s, %s, %s, %s);" % [uv, cell_density, angle_offset, distance_index, chebyshev_power, output, cells]
|