mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
Various wave nodes added
Nodes includes NoiseSineWave, SawtoothWave, SquareWave, TriangleWave
This commit is contained in:
parent
6760b21dc4
commit
b94c01dd61
56
addons/ShaderLib/Maths/Wave/NoiseSineWave.gd
Normal file
56
addons/ShaderLib/Maths/Wave/NoiseSineWave.gd
Normal file
@ -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]
|
8
addons/ShaderLib/Maths/Wave/NoiseSineWave.gdshaderinc
Normal file
8
addons/ShaderLib/Maths/Wave/NoiseSineWave.gdshaderinc
Normal file
@ -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);
|
||||
}
|
38
addons/ShaderLib/Maths/Wave/SawtoothWave.gd
Normal file
38
addons/ShaderLib/Maths/Wave/SawtoothWave.gd
Normal file
@ -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]
|
39
addons/ShaderLib/Maths/Wave/SquareWave.gd
Normal file
39
addons/ShaderLib/Maths/Wave/SquareWave.gd
Normal file
@ -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]
|
37
addons/ShaderLib/Maths/Wave/TriangleWave.gd
Normal file
37
addons/ShaderLib/Maths/Wave/TriangleWave.gd
Normal file
@ -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]
|
Loading…
x
Reference in New Issue
Block a user