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-12-24 20:57:23 +05:30
commit 9d7c679c5b
17 changed files with 391 additions and 28 deletions

View File

@ -1,5 +1,5 @@
# Godot-Shader-Lib
Visual shader node library for Godot engine.
Visual shader node library for Godot engine. The addon supports Godot versions 4.x!
Adds various extra nodes to use in built-in visual shader editor.
# Installation
@ -9,7 +9,22 @@ If you don't immediatly see new nodes under **_Addons_** category, simply reload
# Uninstallation
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="">
<details open>
<summary><h1>Geometry nodes</h1></summary>
<details>
<summary><h3>Node Scale World node</h3></summary>
Provides accees to node scale in world space.
<hr>
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|scale|vec3|None|Node/object scale in world space|
___
</details>
</details>
<hr>
<details open>
<summary><h1>Maths nodes</h1></summary>
<details open>
<summary><h2>Wave</h2></summary>
@ -81,7 +96,7 @@ ___
</details>
</details>
<hr>
<details open="">
<details open>
<summary><h1>Procedural nodes</h1></summary>
<details>
<summary><h3>Checker Board node</h3></summary>
@ -115,6 +130,22 @@ Generates a gradient, or Perlin noise based on input UV. The resulting <b><i>out
|uv|vec2|UV|Input UV value|
|scale|float|none|Noise scale|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|output|float|None|Output noise value|
___
</details>
<details>
<summary><h3>Pseudo Random Noise node</h3></summary>
Generates a pseudo random noise based on input seed. The resulting <b><i>output</i></b> values will be between 0 and 1.
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|seed|float|none|Input seed|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
@ -257,12 +288,13 @@ ___
</details>
</details>
<hr>
<details open="">
<details open>
<summary><h1>UV nodes</h1></summary>
Default value for uv input will be vec2(0, 0) for shader modes <i>PARTICLES</i>, <i>SKY</i> and <i>FOG</i> to avoid errors becouse UV variable is not available for these modes.
<details>
<summary><h3>Flipbook node</h3></summary>
Creates a flipbook, or texture sheet animation, of the UVs supplied to input UV. The amount of tiles on the sheet are defined by the values of the inputs <b><i>rows</i></b> and <b><i>columns</i></b>.
This node can be used to create a texture animation functionality, commonly used for particle effects and sprites.
This node can be used to create a texture animation functionality, commonly used for particle effects and sprites.<br><br><i>This node is only available in shader modes SPATIAL and CANVAS ITEM.</i>
<hr>
**Inputs**
@ -275,6 +307,23 @@ This node can be used to create a texture animation functionality, commonly used
|end frame|int|none|End tile index texture sheet|
|anim speed|float|none|Animation speed|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|uv|vec2|None|Output UV value|
___
</details>
<details>
<summary><h3>Parallax mapping node</h3></summary>
The Parallax Mapping node lets you create a parallax effect that displaces a Material's UVs to create the illusion of depth inside a Material.<br><br><i>This node is only available in shader modes SPATIAL and CANVAS ITEM.</i>
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|height map|sampler2D|none|Height map texture|
|amplitude|float|none|amplitude or depth of the effect|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
@ -332,6 +381,25 @@ Applies a spherical warping effect similar to a fisheye camera lens to the value
|strength|float|none|Strength of the effect|
|offset|vec2|none|Individual channel offsets|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|uv|vec2|None|Output UV value|
___
</details>
<details>
<summary><h3>Swirl node</h3></summary>
Applies a swirl warping effect similar to a black hole to the value of input UV. Very similar to <b><i>Twirl node</b></i>, key difference is it uses the inverse of vector length (One minus).
<hr>
**Inputs**
|Name|Type|Binding|Description|
|---|---|---|---|
|uv|vec2|UV|Input UV value|
|center|vec2|none|Center reference point|
|strength|float|none|Strength of the effect|
|offset|vec2|none|Individual channel offsets|
**Outputs**
|Name|Type|Binding|Description|
|---|---|---|---|
@ -358,7 +426,7 @@ ___
</details>
<details>
<summary><h3>Twirl node</h3></summary>
Applies a twirl warping effect similar to a black hole to the value of input UV.
Applies a twirl warping effect similar to a black hole to the value of input UV. Very similar to <b><i>Swirl node</b></i>, key difference is it uses the length of a vector.
<hr>
**Inputs**

View File

@ -0,0 +1,45 @@
@tool
class_name VisualShaderNodeGeometryNodeScaleWorld extends VisualShaderNodeCustom
func _get_name() -> String:
return "NodeScaleWorld"
func _get_category() -> String:
return "Geometry"
func _get_description() -> String:
return "Provides accees to node scale in world space."
func _get_input_port_count() -> int:
return 0
func _get_input_port_name(port: int) -> String:
return ""
func _get_return_icon_type() -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_3D
func _get_output_port_count() -> int:
return 1
func _get_output_port_name(port: int) -> String:
return "scale"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_3D
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
match mode:
0:
return true
1:
return type==0
_:
return false
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("NodeScaleWorld.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
return output_vars[0] + " = geometry_node_scale_world(MODEL_MATRIX);"

View File

@ -0,0 +1,11 @@
vec3 geometry_node_scale_world(mat4 model_matrix){
vec3 _axis_x = model_matrix[0].xyz;
vec3 _axis_y = model_matrix[1].xyz;
vec3 _axis_z = model_matrix[2].xyz;
float _scale_x = length(_axis_x);
float _scale_y = length(_axis_y);
float _scale_z = length(_axis_z);
return vec3(_scale_x, _scale_y, _scale_z);
}

View File

@ -0,0 +1,39 @@
@tool
class_name VisualShaderNodePseudoRandomNoise extends VisualShaderNodeCustom
func _init() -> void:
set_input_port_default_value(0, 0.0)
output_port_for_preview = 0
func _get_name() -> String:
return "PseudoRandomNoise"
func _get_category() -> String:
return "Procedural/Noise"
func _get_description() -> String:
return "Generates a pseudo random noise based on input seed."
func _get_return_icon_type() -> PortType:
return PORT_TYPE_SCALAR
func _get_input_port_count() -> int:
return 1
func _get_input_port_name(port: int) -> String:
return "seed"
func _get_input_port_type(port: int) -> PortType:
return PORT_TYPE_SCALAR
func _get_output_port_count() -> int:
return 1
func _get_output_port_name(port: int) -> String:
return "output"
func _get_output_port_type(port: int) -> PortType:
return PORT_TYPE_SCALAR
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
return output_vars[0] + " = fract(sin(dot(UV.xy + vec2(%s), vec2(12.9898,78.233))) * 43758.5453123);" % input_vars[0]

View File

@ -7,12 +7,12 @@ float value_noise(vec2 uv){
vec2 _fraction = fract(uv);
_fraction = _fraction * _fraction * (3.0 - 2.0 * _fraction);
vec2 _corner = vec2(1.0, 0.0);
float _c0 = noise_random_value(_floor + _corner.yy);
float _c1 = noise_random_value(_floor + _corner.xy);
float _c2 = noise_random_value(_floor + _corner.yx);
float _c3 = noise_random_value(_floor + _corner.xx);
vec2 _blur = smoothstep(0.0, 1.0, _fraction);
float mix_one = mix(_c0, _c1, _blur.x) + (_c2 - _c0) * _blur.y * (1.0 - _blur.x) + (_c3 - _c1) * _blur.x * _blur.y;
return mix_one;
@ -22,7 +22,7 @@ float simple_noise(vec2 uv, float scale){
int octaves = 6;
float amplitude = 0.25;
float value = 0.0;
for(int i = 0; i < octaves; i++) {
value += amplitude * value_noise(scale * uv);
amplitude *= 0.85;

View File

@ -64,8 +64,21 @@ func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("FlipbookUV.gdshaderinc").code
return code
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
match mode:
0, 1:
return true
_:
return false
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -0,0 +1,62 @@
@tool
class_name VisualShaderNodeUVParallaxMapping extends VisualShaderNodeCustom
func _init() -> void:
_set_input_port_default_value(1, 1.0)
func _get_name() -> String:
return "ParallaxMapping"
func _get_category() -> String:
return "UV"
func _get_description() -> String:
return "The Parallax Mapping node lets you create a parallax effect that displaces a Material's UVs to create the illusion of depth inside a Material."
func _get_return_icon_type() -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_2D
func _get_input_port_count() -> int:
return 2
func _get_input_port_name(port: int) -> String:
match port:
0:
return "heightMap"
1:
return "amplitude"
return ""
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
match port:
0:
return PORT_TYPE_SAMPLER
_:
return PORT_TYPE_SCALAR
func _get_output_port_count() -> int:
return 1
func _get_output_port_name(port: int) -> String:
return "uv"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_2D
func _is_available(mode: Shader.Mode, type: VisualShader.Type) -> bool:
match mode:
0, 1:
return true
_:
return false
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("ParallaxMappingUV.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var height_map: String = input_vars[0]
var amplitude: String = input_vars[1]
if !height_map:
return output_vars[0] + " = UV;"
return output_vars[0] + " = parallax_mapping_uv(%s, -%s, UV, TANGENT, NORMAL, BINORMAL, VIEW);" % [height_map, amplitude];

View File

@ -0,0 +1,17 @@
vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_dir_tangent)
{
height = height * amplitude - amplitude / 2.0;
vec3 _vector = view_dir_tangent;
_vector.y += 0.42;
return height * (_vector.xz / _vector.y);
}
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view)
{
float depth = amplitude / 10.0;
mat3 _tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE
vec3 _view_tangent = transpose(_tangent_matrix) * view;
float _parallaxHeight = texture(height, uv).r;
vec2 _parallaxOffset = parallax_mapping_uv_offset_1_step(_parallaxHeight, depth, _view_tangent);
return _parallaxOffset + uv;
}

View File

@ -57,7 +57,13 @@ func _get_global_code(mode: Shader.Mode) -> String:
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -59,7 +59,13 @@ func _get_global_code(mode: Shader.Mode) -> String:
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -1,16 +1,10 @@
vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees){
float _angle = rotation;
if(use_degrees){
rotation = rotation * (3.1415926/180.0);
_angle = rotation * (3.1415926/180.0);
}
vec2 _uv = uv;
_uv -= center;
float _s = sin(rotation);
float _c = cos(rotation);
mat2 _rotation_matrix = mat2(vec2(_c, -_s), vec2(_s, _c));
_rotation_matrix *= 0.5;
_rotation_matrix += 0.5;
_rotation_matrix = _rotation_matrix * 2.0 - 1.0;
_uv.xy = _uv.xy * _rotation_matrix;
_uv += center;
return _uv;
vec2 _delta = uv - center;
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
return vec2(_x + center.x, _y + center.y);
}

View File

@ -57,7 +57,13 @@ func _get_global_code(mode: Shader.Mode) -> String:
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -0,0 +1,75 @@
@tool
class_name VisualShaderNodeUVSwirl extends VisualShaderNodeCustom
func _init() -> void:
_set_input_port_default_value(1, Vector2(0.5, 0.5))
_set_input_port_default_value(2, 10.0)
_set_input_port_default_value(3, Vector2(0.0, 0.0))
output_port_for_preview = 0
func _get_name() -> String:
return "Swirl"
func _get_category() -> String:
return "UV"
func _get_description() -> String:
return "Applies a swirl warping effect similar to a black hole to the value of input UV."
func _get_return_icon_type() -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_2D
func _get_input_port_count() -> int:
return 4
func _get_input_port_name(port: int) -> String:
match port:
0:
return "uv"
1:
return "center"
2:
return "strength"
3:
return "offset"
return ""
func _get_input_port_type(port: int) -> VisualShaderNode.PortType:
match port:
0, 1, 3:
return PORT_TYPE_VECTOR_2D
2:
return PORT_TYPE_SCALAR
return PORT_TYPE_SCALAR
func _get_output_port_count() -> int:
return 1
func _get_output_port_name(port: int) -> String:
return "uv"
func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_2D
func _get_global_code(mode: Shader.Mode) -> String:
var code: String = preload("SwirlUV.gdshaderinc").code
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]
var center: String = input_vars[1]
var strength: String = input_vars[2]
var offset: String = input_vars[3]
return output_vars[0] + " = swirl_uv(%s, %s, %s, %s);" % [uv, center, strength, offset]

View File

@ -0,0 +1,8 @@
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 _delta = uv - center;
float _inverse_length = 1.0 - length(_delta);
float _angle = strength * _inverse_length;
float _x = cos(_angle) * _delta.x - sin(_angle) * _delta.y;
float _y = sin(_angle) * _delta.x + cos(_angle) * _delta.y;
return vec2(_x + center.x + offset.x, _y + center.y + offset.y);
}

View File

@ -48,7 +48,13 @@ func _get_output_port_type(port: int) -> VisualShaderNode.PortType:
return PORT_TYPE_VECTOR_2D
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -57,7 +57,13 @@ func _get_global_code(mode: Shader.Mode) -> String:
return code
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
var uv: String = "UV"
var uv: String
match mode:
0, 1:
uv = "UV"
_:
uv = "vec2(0.0)"
if input_vars[0]:
uv = input_vars[0]

View File

@ -11,5 +11,6 @@ config_version=5
[application]
config/name="Godot-shader-lib"
config/features=PackedStringArray("4.1", "Forward Plus")
config/tags=PackedStringArray("addons")
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icons/icon.png"