mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
Pseudo random noise node added
This commit is contained in:
parent
8b1f8d246e
commit
db2384c5df
18
README.md
18
README.md
@ -10,7 +10,7 @@ If you don't immediatly see new nodes under **_Addons_** category, simply reload
|
||||
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>Input nodes</h1></summary>
|
||||
<summary><h1>Geometry nodes</h1></summary>
|
||||
<details>
|
||||
<summary><h3>Node Scale World node</h3></summary>
|
||||
Provides accees to node scale in world space.
|
||||
@ -130,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|
|
||||
|---|---|---|---|
|
||||
|
@ -1,11 +1,11 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeInputNodeScaleWorld extends VisualShaderNodeCustom
|
||||
class_name VisualShaderNodeGeometryNodeScaleWorld extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "NodeScaleWorld"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Input"
|
||||
return "Geometry"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Provides accees to node scale in world space."
|
||||
@ -42,4 +42,4 @@ 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:
|
||||
return output_vars[0] + " = node_scale_world(MODEL_MATRIX);"
|
||||
return output_vars[0] + " = geometry_node_scale_world(MODEL_MATRIX);"
|
@ -1,4 +1,4 @@
|
||||
vec3 node_scale_world(mat4 model_matrix){
|
||||
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;
|
39
addons/ShaderLib/Procedural/Noise/PseudoRandomNoise.gd
Normal file
39
addons/ShaderLib/Procedural/Noise/PseudoRandomNoise.gd
Normal 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]
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user