1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-07 01:43:35 +08:00

Merge branch 'development'

This commit is contained in:
Digvijaysinh Gohil 2023-10-15 15:09:19 +05:30
commit 5ece7a3bd3
6 changed files with 249 additions and 0 deletions

View File

@ -8,6 +8,77 @@ Copy the contents of **_addons/ShaderLib_** into the same folder in your project
Delete the contents of **_addons/ShaderLib_** folder from your project. Make sure to delete it using the Godot editor instead of your default file system program.
# Nodes documentation
<details open="">
<summary><h1>Maths nodes</h1></summary>
<details>
<summary><h2>Wave</h2></summary>
<details>
<summary><h3>Noise Sine Wave node</h3></summary>
Returns the sine of the value of input <b><i>in</i></b>. For variance, psuedo-random noise is added to the amplitude of the sine wave, within a range determined by input <b><i>min max</i></b>.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|Dynamic vector|none|Input value|
|min max|vec2|none|Minimum and Maximum values for noise intensity|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|Dynamic vector|None|Output value|
___
</details>
<details>
<summary><h3>Sawtooth Wave node</h3></summary>
Returns a sawtooth wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|Dynamic vector|none|Input value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|Dynamic vector|None|Output value|
___
</details>
<details>
<summary><h3>Square Wave node</h3></summary>
Returns a square wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|Dynamic vector|none|Input value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|Dynamic vector|None|Output value|
___
</details>
<details>
<summary><h3>Triangle Wave node</h3></summary>
Returns a triangle wave from the value of input <b><i>in</i></b>. Resulting output values will be between -1 and 1.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|in|Dynamic vector|none|Input value|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|out|Dynamic vector|None|Output value|
___
</details>
</details>
</details>
<details open="">
<summary><h1>Procedural nodes</h1></summary>
<details>
<summary><h3>Checker Board node</h3></summary>

View 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]

View 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);
}

View 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]

View 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]

View 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]