diff --git a/shaderV/README.md b/shaderV/README.md new file mode 100644 index 0000000..f5d7782 --- /dev/null +++ b/shaderV/README.md @@ -0,0 +1,3 @@ +# ShaderV - VisualShader plugin for Godot Engine 4.x + +https://github.com/arkology/ShaderV diff --git a/shaderV/perlin3d.gd b/shaderV/perlin3d.gd new file mode 100644 index 0000000..8695bcb --- /dev/null +++ b/shaderV/perlin3d.gd @@ -0,0 +1,74 @@ +@tool +extends VisualShaderNodeCustom +class_name VisualShaderNodeNoisePerlin3d + +func _init(): + set_input_port_default_value(1, Vector3(0, 0, 0)) + set_input_port_default_value(2, 5.0) + set_input_port_default_value(3, 0.0) + +func _get_name() -> String: + return "PerlinNoise3D" + +func _get_category() -> String: + return "RGBA" + +func _get_subcategory() -> String: + return "Noise" + +func _get_description() -> String: + return "Classic 3d perlin noise" + +func _get_return_icon_type(): + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_input_port_count() -> int: + return 4 + +func _get_input_port_name(port: int): + match port: + 0: + return "uv" + 1: + return "offset" + 2: + return "scale" + 3: + return "time" + +func _get_input_port_type(port: int): + match port: + 0: + return VisualShaderNode.PORT_TYPE_VECTOR_3D + 1: + return VisualShaderNode.PORT_TYPE_VECTOR_3D + 2: + return VisualShaderNode.PORT_TYPE_SCALAR + 3: + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int): + match port: + 0: + return "result" + +func _get_output_port_type(port: int): + match port: + 0: + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_global_code(mode): + var path = self.get_script().get_path().get_base_dir() + return '#include "' + path + '/perlin3d.gdshaderinc"' + +func _get_code(input_vars, output_vars, mode, type): + var uv = "UV" + + if input_vars[0]: + uv = input_vars[0] + + return "%s = _perlin3dNoiseFunc(vec3((%s.xy+%s.xy) * %s, %s));" % [ +output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3]] diff --git a/shaderV/perlin3d.gdshaderinc b/shaderV/perlin3d.gdshaderinc new file mode 100644 index 0000000..0c5568a --- /dev/null +++ b/shaderV/perlin3d.gdshaderinc @@ -0,0 +1,70 @@ +float _perlin3dNoiseFunc(vec3 P) { + vec3 Pi0 = floor(P); + vec3 Pi1 = Pi0 + vec3(1.0); + Pi0 = Pi0 - floor(Pi0 * (1.0 / 289.0)) * 289.0; + Pi1 = Pi1 - floor(Pi1 * (1.0 / 289.0)) * 289.0; + vec3 Pf0 = fract(P); + vec3 Pf1 = Pf0 - vec3(1.0); + vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + vec4 iy = vec4(Pi0.yy, Pi1.yy); + vec4 iz0 = vec4(Pi0.z); + vec4 iz1 = vec4(Pi1.z); + + vec4 ixy = (((((((ix*34.0)+1.0)*ix)-floor(((ix*34.0)+1.0)*ix*(1.0/289.0))*289.0 + iy)*34.0)+1.0)* + ((((ix*34.0)+1.0)*ix)-floor(((ix*34.0)+1.0)*ix*(1.0/289.0))*289.0 + iy))- + floor(((((((ix*34.0)+1.0)*ix)-floor(((ix*34.0)+1.0)*ix*(1.0/289.0))*289.0 + iy)*34.0)+1.0)* + ((((ix*34.0)+1.0)*ix)-floor(((ix*34.0)+1.0)*ix*(1.0/289.0))*289.0 + iy)*(1.0/289.0))*289.0; + vec4 ixy0 = ((((ixy + iz0)*34.0)+1.0)*(ixy + iz0))-floor((((ixy + iz0)*34.0)+1.0)*(ixy + iz0)*(1.0/289.0))*289.0; + vec4 ixy1 = ((((ixy + iz1)*34.0)+1.0)*(ixy + iz1))-floor((((ixy + iz1)*34.0)+1.0)*(ixy + iz1)*(1.0/289.0))*289.0; + + vec4 gx0 = ixy0 * (1.0 / 7.0); + vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5; + gx0 = fract(gx0); + vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0); + vec4 sz0 = step(gz0, vec4(0.0)); + gx0 -= sz0 * (step(0.0, gx0) - 0.5); + gy0 -= sz0 * (step(0.0, gy0) - 0.5); + + vec4 gx1 = ixy1 * (1.0 / 7.0); + vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5; + gx1 = fract(gx1); + vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1); + vec4 sz1 = step(gz1, vec4(0.0)); + gx1 -= sz1 * (step(0.0, gx1) - 0.5); + gy1 -= sz1 * (step(0.0, gy1) - 0.5); + + vec3 g000 = vec3(gx0.x,gy0.x,gz0.x); + vec3 g100 = vec3(gx0.y,gy0.y,gz0.y); + vec3 g010 = vec3(gx0.z,gy0.z,gz0.z); + vec3 g110 = vec3(gx0.w,gy0.w,gz0.w); + vec3 g001 = vec3(gx1.x,gy1.x,gz1.x); + vec3 g101 = vec3(gx1.y,gy1.y,gz1.y); + vec3 g011 = vec3(gx1.z,gy1.z,gz1.z); + vec3 g111 = vec3(gx1.w,gy1.w,gz1.w); + + vec4 norm0 = 1.79284291400159 - 0.85373472095314 * vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)); + g000 *= norm0.x; + g010 *= norm0.y; + g100 *= norm0.z; + g110 *= norm0.w; + vec4 norm1 = 1.79284291400159 - 0.85373472095314 * vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)); + g001 *= norm1.x; + g011 *= norm1.y; + g101 *= norm1.z; + g111 *= norm1.w; + + float n000 = dot(g000, Pf0); + float n100 = dot(g100, vec3(Pf1.x, Pf0.yz)); + float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z)); + float n110 = dot(g110, vec3(Pf1.xy, Pf0.z)); + float n001 = dot(g001, vec3(Pf0.xy, Pf1.z)); + float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z)); + float n011 = dot(g011, vec3(Pf0.x, Pf1.yz)); + float n111 = dot(g111, Pf1); + + vec3 fade_xyz = Pf0 * Pf0 * Pf0 * (Pf0 * (Pf0 * 6.0 - 15.0) + 10.0); + vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z); + vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y); + float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); + return (2.2 * n_xyz + 1.0) * 0.5; +} \ No newline at end of file diff --git a/shaderV/worley2x2x2.gd b/shaderV/worley2x2x2.gd new file mode 100644 index 0000000..8270ea7 --- /dev/null +++ b/shaderV/worley2x2x2.gd @@ -0,0 +1,75 @@ +@tool +extends VisualShaderNodeCustom +class_name VisualShaderNodeNoiseWorley2x2x2 + +func _init(): + set_input_port_default_value(1, Vector3(0, 0, 0)) + set_input_port_default_value(2, 5.0) + set_input_port_default_value(3, 1.0) + set_input_port_default_value(4, 0.0) + +func _get_name() -> String: + return "WorleyNoise2x2x2" + +func _get_category() -> String: + return "RGBA" + +func _get_subcategory() -> String: + return "Noise" + +func _get_description() -> String: + return "2x2x2 worley noise" + +func _get_return_icon_type(): + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_input_port_count() -> int: + return 5 + +func _get_input_port_name(port: int): + match port: + 0: + return "uv" + 1: + return "offset" + 2: + return "scale" + 3: + return "jitter" + 4: + return "time" + +func _get_input_port_type(port: int): + match port: + 0: + return VisualShaderNode.PORT_TYPE_VECTOR_3D + 1: + return VisualShaderNode.PORT_TYPE_VECTOR_3D + 2: + return VisualShaderNode.PORT_TYPE_SCALAR + 3: + return VisualShaderNode.PORT_TYPE_SCALAR + 4: + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_output_port_count() -> int: + return 1 + +func _get_output_port_name(port: int) -> String: + return "F1" + +func _get_output_port_type(port): + return VisualShaderNode.PORT_TYPE_SCALAR + +func _get_global_code(mode): + var path = self.get_script().get_path().get_base_dir() + return '#include "' + path + '/worley2x2x2.gdshaderinc"' + +func _get_code(input_vars, output_vars, mode, type): + var uv = "UV" + + if input_vars[0]: + uv = input_vars[0] + + return "%s = _cellular2x2x2NoiseFunc(vec3((%s.xy + %s.xy) * %s, %s), min(max(%s, 0.0), 1.0));" % [ +output_vars[0], uv, input_vars[1], input_vars[2], input_vars[4], input_vars[3]] diff --git a/shaderV/worley2x2x2.gdshaderinc b/shaderV/worley2x2x2.gdshaderinc new file mode 100644 index 0000000..4e49548 --- /dev/null +++ b/shaderV/worley2x2x2.gdshaderinc @@ -0,0 +1,34 @@ +float _cellular2x2x2NoiseFunc(vec3 P, float _jitter_w2x2x2) { + float K = 0.142857142857; + float Ko = 0.428571428571; + float K2 = 0.020408163265306; + float Kz = 0.166666666667; + float Kzo = 0.416666666667; + + vec3 Pi = floor(P)- floor(floor(P) * (1.0 / 289.0)) * 289.0; + vec3 Pf = fract(P); + vec4 Pfx = Pf.x + vec4(0.0, -1.0, 0.0, -1.0); + vec4 Pfy = Pf.y + vec4(0.0, 0.0, -1.0, -1.0); + vec4 p = (34.0*(Pi.x+vec4(0.0,1.0,0.0,1.0))+1.0)*(Pi.x+vec4(0.0,1.0,0.0,1.0))-floor((34.0*(Pi.x+vec4(0.0,1.0,0.0,1.0))+1.0)*(Pi.x+vec4(0.0,1.0,0.0,1.0))*(1.0/289.0))*289.0; + p = (34.0*(p+Pi.y+vec4(0.0,0.0,1.0,1.0))+1.0)*(p+Pi.y+vec4(0.0,0.0,1.0,1.0))-floor((34.0*(p+Pi.y+vec4(0.0,0.0,1.0,1.0))+1.0)*(p+Pi.y+vec4(0.0,0.0,1.0,1.0))*(1.0/289.0))*289.0; + vec4 p1 = (34.0*(p+Pi.z)+1.0)*(p+Pi.z)-floor((34.0*(p+Pi.z)+1.0)*(p+Pi.z)*(1.0/289.0))*289.0; + vec4 p2 = (34.0*(p+Pi.z+vec4(1.0))+1.0)*(p+Pi.z+vec4(1.0))-floor((34.0*(p+Pi.z+vec4(1.0))+1.0)*(p+Pi.z+vec4(1.0))*(1.0/289.0))*289.0; + vec4 ox1 = fract(p1*K) - Ko; + vec4 oy1 = (floor(p1*K) - floor(floor(p1*K) * (1.0 / 7.0)) * 7.0)*K - Ko; + vec4 oz1 = floor(p1*K2)*Kz - Kzo; + vec4 ox2 = fract(p2*K) - Ko; + vec4 oy2 = (floor(p2*K) - floor(floor(p2*K) * (1.0 / 7.0)) * 7.0)*K - Ko; + vec4 oz2 = floor(p2*K2)*Kz - Kzo; + vec4 dx1 = Pfx + _jitter_w2x2x2*ox1; + vec4 dy1 = Pfy + _jitter_w2x2x2*oy1; + vec4 dz1 = Pf.z + _jitter_w2x2x2*oz1; + vec4 dx2 = Pfx + _jitter_w2x2x2*ox2; + vec4 dy2 = Pfy + _jitter_w2x2x2*oy2; + vec4 dz2 = Pf.z - 1.0 + _jitter_w2x2x2*oz2; + vec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1; + vec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2; + d1 = min(d1, d2); + d1.xy = min(d1.xy, d1.wz); + d1.x = min(d1.x, d1.y); + return sqrt(d1.x); +} \ No newline at end of file diff --git a/shaders/bg.tres b/shaders/bg.tres index c1c0ad9..d531f22 100644 --- a/shaders/bg.tres +++ b/shaders/bg.tres @@ -60,9 +60,9 @@ render_mode blend_mix; // PerlinNoise3D -#include \"res://shaderV/rgba/noise/perlin3d.gdshaderinc\" +#include \"res://shaderV/perlin3d.gdshaderinc\" // WorleyNoise2x2x2 -#include \"res://shaderV/rgba/noise/worley2x2x2.gdshaderinc\" +#include \"res://shaderV/worley2x2x2.gdshaderinc\" void fragment() { // Input:24 diff --git a/shaders/blob2.tres b/shaders/blob2.tres index e0afa4a..af794fd 100644 --- a/shaders/blob2.tres +++ b/shaders/blob2.tres @@ -136,7 +136,7 @@ uniform float uRadius = 0.20000000298023; // WorleyNoise2x2x2 -#include \"res://shaderV/rgba/noise/worley2x2x2.gdshaderinc\" +#include \"res://shaderV/worley2x2x2.gdshaderinc\" // GlobalExpression:0 vec2 random2(vec2 st) { st = vec2(dot(st, vec2(127.1, 311.7)), @@ -281,7 +281,6 @@ void fragment() { } " -graph_offset = Vector2(-8, 0) mode = 1 flags/light_only = false nodes/vertex/0/position = Vector2(-1100, -800)