mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-19 11:56:01 +08:00
Pseudo random noise node added
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user