mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-05 00:53:36 +08:00
Manhattan Distance node added
This commit is contained in:
parent
41f016feca
commit
0d5c68fb1f
@ -0,0 +1,4 @@
|
||||
float manhattan_distance_2d(vec2 point1, vec2 point2) {
|
||||
vec2 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y);
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
float manhattan_distance_3d(vec3 point1, vec3 point2) {
|
||||
vec3 d = point1 - point2;
|
||||
return abs(d.x) + abs(d.y) + abs(d.z);
|
||||
}
|
88
addons/ShaderLib/Maths/Vector/Distance/ManhattanDistance.gd
Normal file
88
addons/ShaderLib/Maths/Vector/Distance/ManhattanDistance.gd
Normal file
@ -0,0 +1,88 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeMathsManhattanDistance extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "ManhattanDistance"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Vector/Distance"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the distance between two points using Manhattan distance matrix."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
_:
|
||||
return "b"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_2D
|
||||
_:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "distance"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_property_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_property_name(index: int) -> String:
|
||||
return ""
|
||||
|
||||
func _get_property_default_index(index: int) -> int:
|
||||
return 0
|
||||
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
code = preload("Manhattan2D.gdshaderinc").code
|
||||
_:
|
||||
code = preload("Manhattan3D.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var point_a: String
|
||||
var point_b: String
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
point_a = "vec2(0)"
|
||||
point_b = "vec2(0)"
|
||||
_:
|
||||
point_b = "vec3(0)"
|
||||
point_a = "vec3(0)"
|
||||
|
||||
if input_vars[0]:
|
||||
point_a = input_vars[0]
|
||||
|
||||
if input_vars[1]:
|
||||
point_b = input_vars[1]
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = manhattan_distance_2d(%s, %s);" % [point_a, point_b]
|
||||
_:
|
||||
return output_vars[0] + " = manhattan_distance_3d(%s, %s);" % [point_a, point_b]
|
||||
|
@ -32,6 +32,10 @@ For example if you want to rotate UV in your **_.gdshader_** file, you can use `
|
||||
|
||||
<h3> Vector</h3>
|
||||
|
||||
<h3>  Distance</h3>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Maths/Vector/Distance/ManhattanDistance.md">   Manhattan Distance node</a></h4>
|
||||
|
||||
<h4><a href="/documentation/Nodes/Maths/Vector/Project.md">  Project node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Maths/Vector/ProjectOnPlane.md">  Project On Plane node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Maths/Vector/VectorTransform.md">  Vector Transform node</a></h4>
|
||||
|
@ -0,0 +1,20 @@
|
||||
# Manhattan Distance node
|
||||
Returns the distance between two points using Manhattan distance matrix.
|
||||
<hr>
|
||||
|
||||
**Controls**
|
||||
|Options|Description|
|
||||
|---|---|
|
||||
|Vector2, Vector3|Vector type to use for calculation|
|
||||
|
||||
**Inputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|a|Dynamic vector|none|Point a|
|
||||
|b|Dynamic vector|none|Point b|
|
||||
|
||||
**Outputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|distance|float|None|Distance between 2 points|
|
||||
___
|
Loading…
x
Reference in New Issue
Block a user