mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-20 12:25:59 +08:00
Maths nodes refactored, Smoothmin and Smoothmax nodes added
This commit is contained in:
@ -62,6 +62,10 @@ func _get_property_name(index: int) -> String:
|
||||
func _get_property_options(index: int) -> PackedStringArray:
|
||||
return ["Vector2", "Vector3"]
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("Project.gdshaderinc").code
|
||||
return code
|
||||
|
||||
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]
|
||||
@ -69,6 +73,6 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = vec2(%s.xy) * (dot(%s.xy, %s.xy) / dot(%s.xy, %s.xy));" % [vector_b, vector_a, vector_b, vector_b, vector_b]
|
||||
return output_vars[0] + " = project_2d(%s, %s);" % [vector_a, vector_b]
|
||||
_:
|
||||
return output_vars[0] + " = %s * (dot(%s, %s) / dot(%s, %s));" % [vector_b, vector_a, vector_b, vector_b, vector_b]
|
||||
return output_vars[0] + " = project_3d(%s, %s);" % [vector_a, vector_b]
|
||||
|
7
addons/ShaderLib/Maths/Vector/Project.gdshaderinc
Normal file
7
addons/ShaderLib/Maths/Vector/Project.gdshaderinc
Normal file
@ -0,0 +1,7 @@
|
||||
vec2 project_2d(vec2 a, vec2 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
||||
|
||||
vec3 project_3d(vec3 a, vec3 b) {
|
||||
return b * (dot(a, b) / dot(b, b));
|
||||
}
|
@ -11,12 +11,7 @@ func _get_description() -> String:
|
||||
return "Projects a vector onto a plane defined by a normal orthogonal to the plane."
|
||||
|
||||
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
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 2
|
||||
@ -29,12 +24,7 @@ func _get_input_port_name(port: int) -> String:
|
||||
return "plane normal"
|
||||
|
||||
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
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
@ -43,31 +33,13 @@ 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
|
||||
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"]
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("ProjectOnPlane.gdshaderinc").code
|
||||
return code
|
||||
|
||||
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 plane_normal: String = input_vars[1]
|
||||
var vector_index: int = get_option_index(0)
|
||||
match vector_index:
|
||||
0:
|
||||
return output_vars[0] + " = %s.xy - (%s.xy * (dot(%s.xy, %s.xy) / dot(%s.xy, %s.xy)));" % [vector_a, plane_normal, vector_a, plane_normal, plane_normal, plane_normal]
|
||||
_:
|
||||
return output_vars[0] + " = %s - (%s * (dot(%s, %s) / dot(%s, %s)));" % [vector_a, plane_normal, vector_a, plane_normal, plane_normal, plane_normal]
|
||||
return output_vars[0] + " = project_on_plane(%s, %s);" % [vector_a, plane_normal]
|
||||
|
3
addons/ShaderLib/Maths/Vector/ProjectOnPlane.gdshaderinc
Normal file
3
addons/ShaderLib/Maths/Vector/ProjectOnPlane.gdshaderinc
Normal file
@ -0,0 +1,3 @@
|
||||
vec3 project_on_plane(vec3 vector, vec3 plane_normal) {
|
||||
return vector - (plane_normal * (dot(vector, plane_normal) / dot(plane_normal, plane_normal)));
|
||||
}
|
Reference in New Issue
Block a user