diff --git a/addons/ShaderLib/Maths/Wave/NoiseSineWave.gd b/addons/ShaderLib/Maths/Wave/NoiseSineWave.gd new file mode 100644 index 0000000..f7acc62 --- /dev/null +++ b/addons/ShaderLib/Maths/Wave/NoiseSineWave.gd @@ -0,0 +1,56 @@ +@tool +class_name VisualShaderNodeMathsNoiseSineWave extends VisualShaderNodeCustom + +func _init() -> void: + set_input_port_default_value(1, Vector2(0.0, 1.0)) + +func _get_name() -> String: + return "NoiseSineWave" + +func _get_category() -> String: + return "Maths/Wave" + +func _get_description() -> String: + return "Returns the sine of the value of input in. For variance, psuedo-random noise is added to the amplitude of the sine wave, within a range determined by input min max." + +func _get_return_icon_type() -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_input_port_count() -> int: + return 2 + +func _get_input_port_name(port: int) -> String: + match port: + 0: + return "in" + 1, _: + return "min max" + +func _get_input_port_type(port: int) -> VisualShaderNode.PortType: + match port: + 0: + return PORT_TYPE_VECTOR_4D + 1: + return PORT_TYPE_VECTOR_2D + return PORT_TYPE_SCALAR + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "out" + +func _get_output_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_global_code(mode: Shader.Mode) -> String: + var code: String = preload("NoiseSineWave.gdshaderinc").code + return code + +func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: + var input: String = "vec4(0.0)" + if input_vars[0]: + input = input_vars[0] + + var min_max: String = input_vars[1] + return output_vars[0] + " = noise_sine_wave(%s, %s);" % [input, min_max] diff --git a/addons/ShaderLib/Maths/Wave/NoiseSineWave.gdshaderinc b/addons/ShaderLib/Maths/Wave/NoiseSineWave.gdshaderinc new file mode 100644 index 0000000..259c210 --- /dev/null +++ b/addons/ShaderLib/Maths/Wave/NoiseSineWave.gdshaderinc @@ -0,0 +1,8 @@ +vec4 noise_sine_wave(vec4 input, vec2 min_max) +{ + vec4 _sin_in = sin(input); + vec4 _sin_in_offset = sin(input + 1.0); + vec4 _random_number = fract(sin((_sin_in - _sin_in_offset) * (12.9898 + 78.233))*43758.5453); + float _noise = mix(min_max.x, min_max.y, _random_number.x); + return _sin_in + vec4(_noise); +} \ No newline at end of file diff --git a/addons/ShaderLib/Maths/Wave/SawtoothWave.gd b/addons/ShaderLib/Maths/Wave/SawtoothWave.gd new file mode 100644 index 0000000..93fcd4b --- /dev/null +++ b/addons/ShaderLib/Maths/Wave/SawtoothWave.gd @@ -0,0 +1,38 @@ +@tool +class_name VisualShaderNodeMathsSawtoothWave extends VisualShaderNodeCustom + +func _get_name() -> String: + return "SawtoothWave" + +func _get_category() -> String: + return "Maths/Wave" + +func _get_description() -> String: + return "Returns a sawtooth wave from the value of input in. Resulting output values will be between -1 and 1." + +func _get_return_icon_type() -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_input_port_count() -> int: + return 1 + +func _get_input_port_name(port: int) -> String: + return "in" + +func _get_input_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "out" + +func _get_output_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: + var input: String = "vec4(0.0)" + if input_vars[0]: + input = input_vars[0] + return output_vars[0] + " = 2.0 * (%s - floor(0.5 + %s));" % [input, input] diff --git a/addons/ShaderLib/Maths/Wave/SquareWave.gd b/addons/ShaderLib/Maths/Wave/SquareWave.gd new file mode 100644 index 0000000..b359f1f --- /dev/null +++ b/addons/ShaderLib/Maths/Wave/SquareWave.gd @@ -0,0 +1,39 @@ +@tool +class_name VisualShaderNodeMathsSquareWave extends VisualShaderNodeCustom + + +func _get_name() -> String: + return "SquareWave" + +func _get_category() -> String: + return "Maths/Wave" + +func _get_description() -> String: + return "Returns a square wave from the value of input in. Resulting output values will be between -1 and 1." + +func _get_return_icon_type() -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_input_port_count() -> int: + return 1 + +func _get_input_port_name(port: int) -> String: + return "input" + +func _get_input_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "out" + +func _get_output_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: + var input: String = "vec4(0.0)" + if input_vars[0]: + input = input_vars[0] + return output_vars[0] + " = 1.0 - 2.0 * round(fract(%s));" % [input] diff --git a/addons/ShaderLib/Maths/Wave/TriangleWave.gd b/addons/ShaderLib/Maths/Wave/TriangleWave.gd new file mode 100644 index 0000000..edec1b7 --- /dev/null +++ b/addons/ShaderLib/Maths/Wave/TriangleWave.gd @@ -0,0 +1,37 @@ +@tool +class_name VisualShaderNodeMathsTriangleWave extends VisualShaderNodeCustom + +func _get_name() -> String: + return "TriangleWave" + +func _get_category() -> String: + return "Maths/Wave" + +func _get_description() -> String: + return "Returns a triangle wave from the value of input in. Resulting output values will be between -1 and 1." + +func _get_return_icon_type() -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_input_port_count() -> int: + return 1 + +func _get_input_port_name(port: int) -> String: + return "in" +func _get_input_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "out" + +func _get_output_port_type(port: int) -> VisualShaderNode.PortType: + return PORT_TYPE_VECTOR_4D + +func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String: + var input: String = "vec4(0.0)" + if input_vars[0]: + input = input_vars[0] + return output_vars[0] + " = 2.0 * abs(2.0 * (%s - floor(0.5 + %s))) - 1.0;" % [input, input]