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:
56
addons/ShaderLib/Maths/Scalar/SmoothMax.gd
Normal file
56
addons/ShaderLib/Maths/Scalar/SmoothMax.gd
Normal file
@ -0,0 +1,56 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMax extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMax"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Scalar"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the maximum value between A and B, but smooths out the intersections of A and B based on T."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
1:
|
||||
return "b"
|
||||
_:
|
||||
return "t"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 0.5
|
||||
_:
|
||||
return 0.0
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "op"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("SmoothMax.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
||||
var b: String = input_vars[1]
|
||||
var t: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = smoothmax(%s, %s, %s);" % [a, b, t]
|
4
addons/ShaderLib/Maths/Scalar/SmoothMax.gdshaderinc
Normal file
4
addons/ShaderLib/Maths/Scalar/SmoothMax.gdshaderinc
Normal file
@ -0,0 +1,4 @@
|
||||
float smoothmax(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / -t, 0, 1);
|
||||
return mix(b, a, h) + t * h * (1. - h);
|
||||
}
|
56
addons/ShaderLib/Maths/Scalar/SmoothMin.gd
Normal file
56
addons/ShaderLib/Maths/Scalar/SmoothMin.gd
Normal file
@ -0,0 +1,56 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeScalarSmoothMin extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "SmoothMin"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Maths/Scalar"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Returns the minimum value between A and B, but smooths out the intersections of A and B based on T."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "a"
|
||||
1:
|
||||
return "b"
|
||||
_:
|
||||
return "t"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
2:
|
||||
return 0.5
|
||||
_:
|
||||
return 0.0
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "op"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("SmoothMin.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var a: String = input_vars[0]
|
||||
var b: String = input_vars[1]
|
||||
var t: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = smoothmin(%s, %s, %s);" % [a, b, t]
|
4
addons/ShaderLib/Maths/Scalar/SmoothMin.gdshaderinc
Normal file
4
addons/ShaderLib/Maths/Scalar/SmoothMin.gdshaderinc
Normal file
@ -0,0 +1,4 @@
|
||||
float smoothmin(float a, float b, float t) {
|
||||
float h = clamp(.5 + .5 * (b - a) / t, 0, 1);
|
||||
return mix(b, a, h) - t * h * (1. - h);
|
||||
}
|
Reference in New Issue
Block a user