mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
Gyroid noise node added
This commit is contained in:
parent
4686b20c51
commit
a7467b8bfd
79
addons/ShaderLib/Procedural/Noise/GyroidNoise.gd
Normal file
79
addons/ShaderLib/Procedural/Noise/GyroidNoise.gd
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
@tool
|
||||||
|
class_name VisualShaderNodeProceduralGyroidNoise extends VisualShaderNodeCustom
|
||||||
|
|
||||||
|
func _init() -> void:
|
||||||
|
output_port_for_preview = 0
|
||||||
|
|
||||||
|
func _get_name() -> String:
|
||||||
|
return "GyroidNoise"
|
||||||
|
|
||||||
|
func _get_category() -> String:
|
||||||
|
return "Procedural/Noise"
|
||||||
|
|
||||||
|
func _get_description() -> String:
|
||||||
|
return "Generates a gyroid noise based on input UV."
|
||||||
|
|
||||||
|
func _get_return_icon_type() -> PortType:
|
||||||
|
return PORT_TYPE_SCALAR
|
||||||
|
|
||||||
|
func _get_input_port_count() -> int:
|
||||||
|
return 5
|
||||||
|
|
||||||
|
func _get_input_port_name(port: int) -> String:
|
||||||
|
match port:
|
||||||
|
0:
|
||||||
|
return "uv"
|
||||||
|
1:
|
||||||
|
return "scale"
|
||||||
|
2:
|
||||||
|
return "ratio"
|
||||||
|
3:
|
||||||
|
return "height"
|
||||||
|
_:
|
||||||
|
return "thickness"
|
||||||
|
|
||||||
|
func _get_input_port_type(port: int) -> PortType:
|
||||||
|
match port:
|
||||||
|
0, 2:
|
||||||
|
return PORT_TYPE_VECTOR_2D
|
||||||
|
_:
|
||||||
|
return PORT_TYPE_SCALAR
|
||||||
|
|
||||||
|
func _get_input_port_default_value(port: int) -> Variant:
|
||||||
|
match port:
|
||||||
|
1:
|
||||||
|
return 2.0
|
||||||
|
2:
|
||||||
|
return Vector2(1, 1)
|
||||||
|
3:
|
||||||
|
return 0.5
|
||||||
|
4:
|
||||||
|
return 0.0
|
||||||
|
_:
|
||||||
|
return null
|
||||||
|
|
||||||
|
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_global_code(mode: Shader.Mode) -> String:
|
||||||
|
var code: String = preload("GyroidNoise.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 = "UV"
|
||||||
|
|
||||||
|
if input_vars[0]:
|
||||||
|
uv = input_vars[0]
|
||||||
|
|
||||||
|
var scale: String = input_vars[1]
|
||||||
|
var ratio: String = input_vars[2]
|
||||||
|
var height: String = input_vars[3]
|
||||||
|
var thickness: String = input_vars[4]
|
||||||
|
|
||||||
|
return output_vars[0] + " = gyroid_noise(%s, %s, %s, %s, %s);" % [uv, scale, ratio, height, thickness]
|
@ -0,0 +1,7 @@
|
|||||||
|
float gyroid_noise(vec2 uv, float scale, vec2 ratio, float height, float thickness) {
|
||||||
|
scale *= 10.;
|
||||||
|
thickness = clamp(thickness, 0., 1.);
|
||||||
|
vec3 vector = vec3(uv, height);
|
||||||
|
vector *= scale;
|
||||||
|
return abs(dot(sin(vector * ratio.x), cos(vector.zxy * ratio.y))) - thickness;
|
||||||
|
}
|
@ -59,6 +59,7 @@ For example if you want to rotate UV in your **_.gdshader_** file, you can use `
|
|||||||
<h3> Noise</h3>
|
<h3> Noise</h3>
|
||||||
|
|
||||||
<h4><a href="/documentation/Nodes/Procedural/Noise/GradientNoise.md">  Gradient Noise node</a></h4>
|
<h4><a href="/documentation/Nodes/Procedural/Noise/GradientNoise.md">  Gradient Noise node</a></h4>
|
||||||
|
<h4><a href="/documentation/Nodes/Procedural/Noise/GyroidNoise.md">  Gyroid Noise node</a></h4>
|
||||||
<h4><a href="/documentation/Nodes/Procedural/Noise/PseudoRandomNoise.md">  Pseudo Random Noise node</a></h4>
|
<h4><a href="/documentation/Nodes/Procedural/Noise/PseudoRandomNoise.md">  Pseudo Random Noise node</a></h4>
|
||||||
<h4><a href="/documentation/Nodes/Procedural/Noise/SimpleNoise.md">  Simple Noise node</a></h4>
|
<h4><a href="/documentation/Nodes/Procedural/Noise/SimpleNoise.md">  Simple Noise node</a></h4>
|
||||||
<h4><a href="/documentation/Nodes/Procedural/Noise/Voronoi.md">  Voronoi node</a></h4>
|
<h4><a href="/documentation/Nodes/Procedural/Noise/Voronoi.md">  Voronoi node</a></h4>
|
||||||
|
18
documentation/Nodes/Procedural/Noise/GyroidNoise.md
Normal file
18
documentation/Nodes/Procedural/Noise/GyroidNoise.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Gyroid Noise node
|
||||||
|
Generates a gyroid noise based on input UV. The resulting <b><i>output</i></b> values will be between 0 and 1.
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
**Inputs**
|
||||||
|
|Name|Type|Binding|Description|
|
||||||
|
|---|---|---|---|
|
||||||
|
|uv|vec2|UV|Input UV value|
|
||||||
|
|scale|float|none|Noise scale|
|
||||||
|
|ratio|vec2|none|Noise ratio for X and Y Axes|
|
||||||
|
|height|vec2|none|Noise height|
|
||||||
|
|thickness|vec2|none|Noise thickness|
|
||||||
|
|
||||||
|
**Outputs**
|
||||||
|
|Name|Type|Binding|Description|
|
||||||
|
|---|---|---|---|
|
||||||
|
|output|float|None|Output noise value|
|
||||||
|
___
|
Loading…
x
Reference in New Issue
Block a user