2024-02-27 22:14:50 +05:30
|
|
|
@tool
|
2024-09-28 00:45:16 +05:30
|
|
|
class_name VisualShaderNodeVectorProject extends ShaderLib
|
2024-02-27 22:14:50 +05:30
|
|
|
|
|
|
|
func _get_name() -> String:
|
|
|
|
return "Project"
|
|
|
|
|
|
|
|
func _get_category() -> String:
|
|
|
|
return "Maths/Vector"
|
|
|
|
|
|
|
|
func _get_description() -> String:
|
|
|
|
return "Projects vector A onto vector B."
|
|
|
|
|
|
|
|
func _get_return_icon_type() -> 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_input_port_count() -> int:
|
|
|
|
return 2
|
|
|
|
|
|
|
|
func _get_input_port_name(port: int) -> String:
|
|
|
|
match port:
|
|
|
|
0:
|
|
|
|
return "vector A"
|
|
|
|
_:
|
|
|
|
return "vector 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 "vector"
|
|
|
|
|
|
|
|
func _get_output_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_property_count() -> int:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
func _get_property_default_index(index: int) -> int:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
func _get_property_name(index: int) -> String:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
func _get_property_options(index: int) -> PackedStringArray:
|
|
|
|
return ["Vector2", "Vector3"]
|
|
|
|
|
2024-07-03 00:01:09 +05:30
|
|
|
func _get_global_code(mode: Shader.Mode) -> String:
|
2024-09-28 00:45:16 +05:30
|
|
|
return "#include \"res://addons/ShaderLib_%s/Maths/Maths.gdshaderinc\"" % [version]
|
2024-07-03 00:01:09 +05:30
|
|
|
|
2024-02-27 22:14:50 +05:30
|
|
|
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
|
|
|
var vector_a: String = input_vars[0]
|
|
|
|
var vector_b: String = input_vars[1]
|
|
|
|
var vector_index: int = get_option_index(0)
|
|
|
|
|
|
|
|
match vector_index:
|
|
|
|
0:
|
2024-07-03 00:01:09 +05:30
|
|
|
return output_vars[0] + " = project_2d(%s, %s);" % [vector_a, vector_b]
|
2024-02-27 22:14:50 +05:30
|
|
|
_:
|
2024-07-03 00:01:09 +05:30
|
|
|
return output_vars[0] + " = project_3d(%s, %s);" % [vector_a, vector_b]
|