└── addons └── VisualShaderExtras ├── AddonExamples ├── Resources │ ├── Credits.md │ ├── DinoSprites - vita.png │ ├── DinoSprites - vita.png.import │ ├── KenneyPrototypeTexture.png │ ├── KenneyPrototypeTexture.png.import │ ├── VisualShaderExtras-Logo-128x128.png │ ├── VisualShaderExtras-Logo-128x128.png.import │ ├── VisualShaderExtras-Logo.png │ ├── VisualShaderExtras-Logo.png.import │ ├── csg_test_scene.tscn │ ├── icon.svg │ └── icon.svg.import ├── examples2D.tscn └── examples3D.tscn ├── BlendModes └── blend_modes.gd ├── ColorAdjustment └── HSVAdjustment.gd ├── Procedural ├── Checkerboard.gd ├── PSRD-Noise2D.gd ├── PSRD-Noise3D.gd ├── RadialGradient.gd └── Shapes │ ├── Box.gd │ ├── Circle.gd │ ├── HyperbolicCross.gd │ ├── Parallelogram.gd │ ├── PreciseBox.gd │ ├── PreciseHyperbolicCross.gd │ ├── Rhombus.gd │ ├── RoundedBox.gd │ ├── Trapezoid.gd │ └── Triangle.gd ├── UV ├── UVFlipbook.gd ├── UVRotate.gd ├── UVTiler.gd ├── UVTwirl.gd └── UVtoSphereCoord.gd └── Wave ├── SawtoothWave.gd ├── SineWave.gd ├── SineWaveAngular.gd ├── SquareWave.gd └── TriangleWave.gd /addons/VisualShaderExtras/AddonExamples/Resources/Credits.md: -------------------------------------------------------------------------------- 1 | # Credits 2 | 3 | * Dino Sprites from [here](https://arks.itch.io/dino-characters) by [@ScissorMarks](https://twitter.com/ScissorMarks) 4 | * Font by [Kenney](https://www.kenney.nl/assets/kenney-fonts) 5 | * KenneyPrototypeTexture by [Kenney](https://www.kenney.nl/assets/prototype-textures) 6 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/DinoSprites - vita.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddy-exe/GodotVisualShader-Extras/0e86e42743258655bd3f37f1d5aafe500601fa32/addons/VisualShaderExtras/AddonExamples/Resources/DinoSprites - vita.png -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/DinoSprites - vita.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://bn8avh1dk262a" 6 | path="res://.godot/imported/DinoSprites - vita.png-91fa8edb8fcf02c7c172cb2495339f77.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://addons/VisualShaderExtras/AddonExamples/Resources/DinoSprites - vita.png" 14 | dest_files=["res://.godot/imported/DinoSprites - vita.png-91fa8edb8fcf02c7c172cb2495339f77.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/high_quality=false 20 | compress/lossy_quality=0.7 21 | compress/hdr_compression=1 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=false 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=0 35 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/KenneyPrototypeTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddy-exe/GodotVisualShader-Extras/0e86e42743258655bd3f37f1d5aafe500601fa32/addons/VisualShaderExtras/AddonExamples/Resources/KenneyPrototypeTexture.png -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/KenneyPrototypeTexture.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://64l2eqbdwv15" 6 | path.s3tc="res://.godot/imported/KenneyPrototypeTexture.png-fe2b2b22e188cf93f2fbf14ad2a64dcd.s3tc.ctex" 7 | metadata={ 8 | "imported_formats": ["s3tc_bptc"], 9 | "vram_texture": true 10 | } 11 | 12 | [deps] 13 | 14 | source_file="res://addons/VisualShaderExtras/AddonExamples/Resources/KenneyPrototypeTexture.png" 15 | dest_files=["res://.godot/imported/KenneyPrototypeTexture.png-fe2b2b22e188cf93f2fbf14ad2a64dcd.s3tc.ctex"] 16 | 17 | [params] 18 | 19 | compress/mode=2 20 | compress/high_quality=false 21 | compress/lossy_quality=0.7 22 | compress/hdr_compression=1 23 | compress/normal_map=0 24 | compress/channel_pack=0 25 | mipmaps/generate=true 26 | mipmaps/limit=-1 27 | roughness/mode=0 28 | roughness/src_normal="" 29 | process/fix_alpha_border=true 30 | process/premult_alpha=false 31 | process/normal_map_invert_y=false 32 | process/hdr_as_srgb=false 33 | process/hdr_clamp_exposure=false 34 | process/size_limit=0 35 | detect_3d/compress_to=0 36 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddy-exe/GodotVisualShader-Extras/0e86e42743258655bd3f37f1d5aafe500601fa32/addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo-128x128.png -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo-128x128.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://im3imr3u2j1y" 6 | path.s3tc="res://.godot/imported/VisualShaderExtras-Logo-128x128.png-da69af67736069c6a7e81ec34981eccf.s3tc.ctex" 7 | metadata={ 8 | "imported_formats": ["s3tc_bptc"], 9 | "vram_texture": true 10 | } 11 | 12 | [deps] 13 | 14 | source_file="res://addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo-128x128.png" 15 | dest_files=["res://.godot/imported/VisualShaderExtras-Logo-128x128.png-da69af67736069c6a7e81ec34981eccf.s3tc.ctex"] 16 | 17 | [params] 18 | 19 | compress/mode=2 20 | compress/high_quality=false 21 | compress/lossy_quality=0.7 22 | compress/hdr_compression=1 23 | compress/normal_map=0 24 | compress/channel_pack=0 25 | mipmaps/generate=true 26 | mipmaps/limit=-1 27 | roughness/mode=0 28 | roughness/src_normal="" 29 | process/fix_alpha_border=true 30 | process/premult_alpha=false 31 | process/normal_map_invert_y=false 32 | process/hdr_as_srgb=false 33 | process/hdr_clamp_exposure=false 34 | process/size_limit=0 35 | detect_3d/compress_to=0 36 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paddy-exe/GodotVisualShader-Extras/0e86e42743258655bd3f37f1d5aafe500601fa32/addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo.png -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://djkhiujfs5d88" 6 | path.s3tc="res://.godot/imported/VisualShaderExtras-Logo.png-318a366c28c6edbc5996d5bdd7d865a4.s3tc.ctex" 7 | metadata={ 8 | "imported_formats": ["s3tc_bptc"], 9 | "vram_texture": true 10 | } 11 | 12 | [deps] 13 | 14 | source_file="res://addons/VisualShaderExtras/AddonExamples/Resources/VisualShaderExtras-Logo.png" 15 | dest_files=["res://.godot/imported/VisualShaderExtras-Logo.png-318a366c28c6edbc5996d5bdd7d865a4.s3tc.ctex"] 16 | 17 | [params] 18 | 19 | compress/mode=2 20 | compress/high_quality=false 21 | compress/lossy_quality=0.7 22 | compress/hdr_compression=1 23 | compress/normal_map=0 24 | compress/channel_pack=0 25 | mipmaps/generate=true 26 | mipmaps/limit=-1 27 | roughness/mode=0 28 | roughness/src_normal="" 29 | process/fix_alpha_border=true 30 | process/premult_alpha=false 31 | process/normal_map_invert_y=false 32 | process/hdr_as_srgb=false 33 | process/hdr_clamp_exposure=false 34 | process/size_limit=0 35 | detect_3d/compress_to=0 36 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/csg_test_scene.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene format=3 uid="uid://b0saq40btdu4x"] 2 | 3 | [node name="CSGTestScene" type="CSGCombiner3D"] 4 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) 5 | 6 | [node name="Back" type="CSGBox3D" parent="."] 7 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -2) 8 | size = Vector3(6, 5, 1) 9 | 10 | [node name="LeftSide" type="CSGBox3D" parent="."] 11 | transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -3, 1, 0.5) 12 | size = Vector3(6, 5, 1) 13 | 14 | [node name="RightSide" type="CSGBox3D" parent="."] 15 | transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 3, 1, 0.5) 16 | size = Vector3(6, 5, 1) 17 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/Resources/icon.svg.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://dkwktkcfupn2y" 6 | path="res://.godot/imported/icon.svg-bdf44d070a9634c19b4956b9b438054a.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://addons/VisualShaderExtras/AddonExamples/Resources/icon.svg" 14 | dest_files=["res://.godot/imported/icon.svg-bdf44d070a9634c19b4956b9b438054a.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/high_quality=false 20 | compress/lossy_quality=0.0 21 | compress/hdr_compression=1 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=true 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=0 35 | svg/scale=1.0 36 | editor/scale_with_editor_scale=false 37 | editor/convert_colors_with_editor_theme=false 38 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/AddonExamples/examples3D.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=23 format=3 uid="uid://cjtocgy6oar8e"] 2 | 3 | [ext_resource type="Texture2D" uid="uid://64l2eqbdwv15" path="res://addons/VisualShaderExtras/AddonExamples/Resources/KenneyPrototypeTexture.png" id="1_n6ldv"] 4 | [ext_resource type="PackedScene" uid="uid://b0saq40btdu4x" path="res://addons/VisualShaderExtras/AddonExamples/Resources/csg_test_scene.tscn" id="2_qiifp"] 5 | [ext_resource type="Script" path="res://addons/VisualShaderExtras/Procedural/PSRD-Noise3D.gd" id="3_se3k6"] 6 | [ext_resource type="Script" path="res://addons/VisualShaderExtras/UV/UVtoSphereCoord.gd" id="4_oensc"] 7 | 8 | [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_dnsta"] 9 | sky_top_color = Color(0.133333, 0.294118, 0.54902, 1) 10 | sky_horizon_color = Color(0.411765, 0.454902, 0.670588, 1) 11 | ground_bottom_color = Color(0.2, 0.180392, 0.34902, 1) 12 | ground_horizon_color = Color(0.411765, 0.454902, 0.670588, 1) 13 | 14 | [sub_resource type="Sky" id="Sky_eybnj"] 15 | sky_material = SubResource("ProceduralSkyMaterial_dnsta") 16 | 17 | [sub_resource type="Environment" id="Environment_7au06"] 18 | background_mode = 2 19 | sky = SubResource("Sky_eybnj") 20 | ambient_light_source = 3 21 | reflected_light_source = 2 22 | tonemap_mode = 3 23 | ssao_radius = 8.1 24 | ssao_intensity = 15.06 25 | sdfgi_enabled = true 26 | 27 | [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wf0fy"] 28 | albedo_texture = ExtResource("1_n6ldv") 29 | uv1_triplanar = true 30 | 31 | [sub_resource type="VisualShaderNodeCustom" id="VisualShaderNodeCustom_bit1y"] 32 | default_input_values = [0, Vector3(1, 1, 1), 1, Vector3(1, 1, 1), 2, 1.0] 33 | initialized = true 34 | script = ExtResource("3_se3k6") 35 | 36 | [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_yel11"] 37 | input_name = "normal" 38 | 39 | [sub_resource type="VisualShader" id="VisualShader_30d6h"] 40 | code = "shader_type spatial; 41 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx; 42 | 43 | 44 | 45 | // PSRDNoise3D 46 | 47 | vec4 __psrdnoise3_permute(vec4 i) { 48 | vec4 im = mod(i, 289.0); 49 | return mod(((im*34.0)+10.0)*im, 289.0); 50 | } 51 | 52 | float psrdnoise3_with_gradient(vec3 x, vec3 period, float alpha, out vec3 gradient) { 53 | const mat3 M = mat3(vec3(0.0, 1.0, 1.0), vec3(1.0, 0.0, 1.0), vec3(1.0, 1.0, 0.0)); 54 | const mat3 Mi = mat3(vec3(-0.5, 0.5, 0.5), vec3(0.5,-0.5, 0.5), vec3(0.5, 0.5,-0.5)); 55 | vec3 uvw = M * x; 56 | vec3 i0 = floor(uvw), f0 = fract(uvw); 57 | vec3 g_ = step(f0.xyx, f0.yzz), l_ = 1.0 - g_; 58 | vec3 g = vec3(l_.z, g_.xy), l = vec3(l_.xy, g_.z); 59 | vec3 o1 = min( g, l ), o2 = max( g, l ); 60 | vec3 i1 = i0 + o1, i2 = i0 + o2, i3 = i0 + vec3(1.0); 61 | vec3 v0 = Mi * i0, v1 = Mi * i1, v2 = Mi * i2, v3 = Mi * i3; 62 | vec3 x0 = x - v0, x1 = x - v1, x2 = x - v2, x3 = x - v3; 63 | if(any(greaterThan(period, vec3(0.0)))) { 64 | vec4 vx = vec4(v0.x, v1.x, v2.x, v3.x); 65 | vec4 vy = vec4(v0.y, v1.y, v2.y, v3.y); 66 | vec4 vz = vec4(v0.z, v1.z, v2.z, v3.z); 67 | if(period.x > 0.0) vx = mod(vx, period.x); 68 | if(period.y > 0.0) vy = mod(vy, period.y); 69 | if(period.z > 0.0) vz = mod(vz, period.z); 70 | i0 = floor(M * vec3(vx.x, vy.x, vz.x) + 0.5); 71 | i1 = floor(M * vec3(vx.y, vy.y, vz.y) + 0.5); 72 | i2 = floor(M * vec3(vx.z, vy.z, vz.z) + 0.5); 73 | i3 = floor(M * vec3(vx.w, vy.w, vz.w) + 0.5); 74 | } 75 | 76 | vec4 hash = __psrdnoise3_permute( __psrdnoise3_permute( __psrdnoise3_permute( 77 | vec4(i0.z, i1.z, i2.z, i3.z )) 78 | + vec4(i0.y, i1.y, i2.y, i3.y )) 79 | + vec4(i0.x, i1.x, i2.x, i3.x )); 80 | vec4 theta = hash * 3.883222077; 81 | vec4 sz = hash * -0.006920415 + 0.996539792; 82 | vec4 psi = hash * 0.108705628; 83 | vec4 Ct = cos(theta), St = sin(theta); 84 | vec4 sz_prime = sqrt( 1.0 - sz*sz ); 85 | vec4 gx, gy, gz; 86 | if(alpha != 0.0) { 87 | vec4 px = Ct * sz_prime, py = St * sz_prime, pz = sz; 88 | vec4 Sp = sin(psi), Cp = cos(psi), Ctp = St*Sp - Ct*Cp; 89 | vec4 qx = mix( Ctp*St, Sp, sz), qy = mix(-Ctp*Ct, Cp, sz); 90 | vec4 qz = -(py*Cp + px*Sp); 91 | vec4 Sa = vec4(sin(alpha)), Ca = vec4(cos(alpha)); 92 | gx = Ca*px + Sa*qx; gy = Ca*py + Sa*qy; gz = Ca*pz + Sa*qz; 93 | } else { 94 | gx = Ct * sz_prime; gy = St * sz_prime; gz = sz; 95 | } 96 | vec3 g0 = vec3(gx.x, gy.x, gz.x), g1 = vec3(gx.y, gy.y, gz.y); 97 | vec3 g2 = vec3(gx.z, gy.z, gz.z), g3 = vec3(gx.w, gy.w, gz.w); 98 | vec4 w = 0.5-vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)); 99 | w = max(w, 0.0); vec4 w2 = w * w, w3 = w2 * w; 100 | vec4 gdotx = vec4(dot(g0,x0), dot(g1,x1), dot(g2,x2), dot(g3,x3)); 101 | float n = dot(w3, gdotx); 102 | vec4 dw = -6.0 * w2 * gdotx; 103 | vec3 dn0 = w3.x * g0 + dw.x * x0; 104 | vec3 dn1 = w3.y * g1 + dw.y * x1; 105 | vec3 dn2 = w3.z * g2 + dw.z * x2; 106 | vec3 dn3 = w3.w * g3 + dw.w * x3; 107 | gradient = 39.5 * (dn0 + dn1 + dn2 + dn3); 108 | return 39.5 * n; 109 | } 110 | 111 | float psrdnoise3(vec3 x, vec3 period, float alpha) { 112 | vec3 gradient; 113 | return psrdnoise3_with_gradient(x, period, alpha, gradient); 114 | } 115 | 116 | 117 | 118 | void fragment() { 119 | // Input:3 120 | vec3 n_out3p0 = NORMAL; 121 | 122 | 123 | float n_out2p0; 124 | // PSRDNoise3D:2 125 | vec3 n_in2p1 = vec3(1.00000, 1.00000, 1.00000); 126 | float n_in2p2 = 1.00000; 127 | { 128 | n_out2p0 = psrdnoise3(n_out3p0.xyz, n_in2p1.xyz, n_in2p2); 129 | } 130 | 131 | 132 | // Output:0 133 | ALBEDO = vec3(n_out2p0); 134 | 135 | 136 | } 137 | " 138 | graph_offset = Vector2(-377.1, -13.3) 139 | nodes/fragment/2/node = SubResource("VisualShaderNodeCustom_bit1y") 140 | nodes/fragment/2/position = Vector2(60, 160) 141 | nodes/fragment/3/node = SubResource("VisualShaderNodeInput_yel11") 142 | nodes/fragment/3/position = Vector2(-260, 160) 143 | nodes/fragment/connections = PackedInt32Array(2, 0, 0, 0, 3, 0, 2, 0) 144 | 145 | [sub_resource type="ShaderMaterial" id="ShaderMaterial_soj5p"] 146 | render_priority = 0 147 | shader = SubResource("VisualShader_30d6h") 148 | 149 | [sub_resource type="SphereMesh" id="SphereMesh_mqqi1"] 150 | radius = 1.0 151 | height = 2.0 152 | 153 | [sub_resource type="TextMesh" id="TextMesh_ju7p1"] 154 | text = "PSRD-Noise3D" 155 | font_size = 70 156 | 157 | [sub_resource type="VisualShaderNodeCustom" id="VisualShaderNodeCustom_owjoy"] 158 | default_input_values = [1, Vector3(0, 0, 0)] 159 | initialized = true 160 | script = ExtResource("4_oensc") 161 | 162 | [sub_resource type="VisualShaderNodeVaryingGetter" id="VisualShaderNodeVaryingGetter_t1x3d"] 163 | varying_name = "vertex_world_coord" 164 | varying_type = 4 165 | 166 | [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_ptblt"] 167 | input_name = "node_position_world" 168 | 169 | [sub_resource type="VisualShaderNodeVaryingSetter" id="VisualShaderNodeVaryingSetter_h2o1j"] 170 | varying_name = "vertex_world_coord" 171 | varying_type = 4 172 | 173 | [sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_nf6jw"] 174 | input_name = "vertex" 175 | 176 | [sub_resource type="VisualShader" id="VisualShader_o1ned"] 177 | code = "shader_type spatial; 178 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx; 179 | 180 | 181 | // Varyings 182 | varying vec3 vertex_world_coord; 183 | 184 | 185 | 186 | // UVtoSphereCoord 187 | 188 | vec2 uv_to_sphere_coord(vec3 sphere_surface_point, vec3 sphere_center) 189 | { 190 | vec3 n = normalize(sphere_surface_point - sphere_center); 191 | float sphere_u = atan(n.x, n.z) / (2.0*PI) + 0.5; 192 | float sphere_v = n.y * 0.5 + 0.5; 193 | return vec2(sphere_u, sphere_v); 194 | } 195 | 196 | 197 | void vertex() { 198 | // Input:3 199 | vec3 n_out3p0 = VERTEX; 200 | 201 | 202 | // VaryingSetter:2 203 | vertex_world_coord = n_out3p0; 204 | 205 | 206 | } 207 | 208 | void fragment() { 209 | // VaryingGetter:3 210 | vec3 n_out3p0 = vertex_world_coord; 211 | 212 | 213 | // Input:4 214 | vec3 n_out4p0 = NODE_POSITION_WORLD; 215 | 216 | 217 | vec2 n_out2p0; 218 | // UVtoSphereCoord:2 219 | { 220 | n_out2p0.xy = uv_to_sphere_coord(n_out3p0.xyz, n_out4p0.xyz); 221 | } 222 | 223 | 224 | // Output:0 225 | ALBEDO = vec3(n_out2p0, 0.0); 226 | 227 | 228 | } 229 | " 230 | varyings/vertex_world_coord = "0,4" 231 | nodes/vertex/2/node = SubResource("VisualShaderNodeVaryingSetter_h2o1j") 232 | nodes/vertex/2/position = Vector2(60, 140) 233 | nodes/vertex/3/node = SubResource("VisualShaderNodeInput_nf6jw") 234 | nodes/vertex/3/position = Vector2(-280, 140) 235 | nodes/vertex/connections = PackedInt32Array(3, 0, 2, 0) 236 | nodes/fragment/2/node = SubResource("VisualShaderNodeCustom_owjoy") 237 | nodes/fragment/2/position = Vector2(60, 160) 238 | nodes/fragment/3/node = SubResource("VisualShaderNodeVaryingGetter_t1x3d") 239 | nodes/fragment/3/position = Vector2(-220, 100) 240 | nodes/fragment/4/node = SubResource("VisualShaderNodeInput_ptblt") 241 | nodes/fragment/4/position = Vector2(-280, 200) 242 | nodes/fragment/connections = PackedInt32Array(2, 0, 0, 0, 3, 0, 2, 0, 4, 0, 2, 1) 243 | 244 | [sub_resource type="ShaderMaterial" id="ShaderMaterial_k2kbm"] 245 | render_priority = 0 246 | shader = SubResource("VisualShader_o1ned") 247 | 248 | [sub_resource type="TextMesh" id="TextMesh_0jqoe"] 249 | text = "Sphere- 250 | Coordinates" 251 | font_size = 70 252 | 253 | [node name="Examples" type="Node3D"] 254 | 255 | [node name="WorldEnvironment" type="WorldEnvironment" parent="."] 256 | environment = SubResource("Environment_7au06") 257 | 258 | [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] 259 | transform = Transform3D(0.989699, -0.110675, 0.0908126, -6.9039e-09, 0.634326, 0.773066, -0.143164, -0.765103, 0.627791, 0, 2.42828, 0) 260 | shadow_enabled = true 261 | 262 | [node name="MainCSG" type="CSGCombiner3D" parent="."] 263 | material_override = SubResource("StandardMaterial3D_wf0fy") 264 | 265 | [node name="FloorCSG" type="CSGBox3D" parent="MainCSG"] 266 | size = Vector3(100, 1, 50) 267 | 268 | [node name="CSGTestScene" parent="MainCSG" instance=ExtResource("2_qiifp")] 269 | 270 | [node name="CSGTestScene2" parent="MainCSG" instance=ExtResource("2_qiifp")] 271 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7, 1.5, 0) 272 | 273 | [node name="ExampleMeshes" type="Node" parent="."] 274 | 275 | [node name="PSRD-Noise3D" type="Node3D" parent="ExampleMeshes"] 276 | 277 | [node name="TestSphere" type="MeshInstance3D" parent="ExampleMeshes/PSRD-Noise3D"] 278 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) 279 | material_override = SubResource("ShaderMaterial_soj5p") 280 | mesh = SubResource("SphereMesh_mqqi1") 281 | 282 | [node name="TextDescription" type="MeshInstance3D" parent="ExampleMeshes/PSRD-Noise3D"] 283 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, -1.4) 284 | mesh = SubResource("TextMesh_ju7p1") 285 | 286 | [node name="SphereCoord" type="Node3D" parent="ExampleMeshes"] 287 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7, 2, 0) 288 | 289 | [node name="TestSphere" type="MeshInstance3D" parent="ExampleMeshes/SphereCoord"] 290 | material_override = SubResource("ShaderMaterial_k2kbm") 291 | mesh = SubResource("SphereMesh_mqqi1") 292 | skeleton = NodePath("../../PSRD-Noise3D") 293 | 294 | [node name="TextDescription" type="MeshInstance3D" parent="ExampleMeshes/SphereCoord"] 295 | transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, -1.4) 296 | mesh = SubResource("TextMesh_0jqoe") 297 | skeleton = NodePath("../../PSRD-Noise3D") 298 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/BlendModes/blend_modes.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name VisualShaderNodeBlendModes 3 | extends VisualShaderNodeCustom 4 | 5 | func _init(): 6 | var op = get_option_index(0) 7 | set_input_port_default_value(2, 0.5) 8 | 9 | func _get_name(): 10 | return "BlendModes" 11 | 12 | func _get_category(): 13 | return "VisualShaderExtras/BlendModes" 14 | 15 | func _get_description(): 16 | return "" 17 | 18 | func _get_return_icon_type(): 19 | return PORT_TYPE_VECTOR_3D 20 | 21 | func _get_property_count(): 22 | return 1 23 | 24 | func _get_property_name(index): 25 | return "" 26 | 27 | func _get_property_options(index: int): 28 | return [ 29 | "Additive", 30 | "AddSub", 31 | "Burn", 32 | "Darken", 33 | "Difference", 34 | "Dissolve", 35 | "Dodge", 36 | "Exclusion", 37 | "GammaDark", 38 | "GammaIllumination", 39 | "GammaLight", 40 | "HardLight", 41 | "HardMix", 42 | "Lighten", 43 | "LinearBurn", 44 | "LinearLight", 45 | "Luminosity", 46 | "Multiply", 47 | "Normal", 48 | "Overlay", 49 | "PinLight", 50 | "Screen", 51 | "SoftLight", 52 | "VividLight" 53 | ] 54 | 55 | func _get_default_input_port(type): 56 | return 0 57 | 58 | func _get_input_port_count(): 59 | var op: int = get_option_index(0) 60 | match op: 61 | # Dissolve 62 | 5: 63 | return 4 64 | # default 65 | _: 66 | return 3 67 | 68 | func _get_input_port_name(port): 69 | var op: int = get_option_index(0) 70 | match op: 71 | # Dissolve 72 | 5: 73 | match port: 74 | 0: 75 | return "Top layer" 76 | 1: 77 | return "Bottom layer" 78 | 2: 79 | return "Opacity" 80 | 3: 81 | return "Noise Seed" 82 | # default 83 | _: 84 | match port: 85 | 0: 86 | return "Top layer" 87 | 1: 88 | return "Bottom layer" 89 | 2: 90 | return "Opacity" 91 | 92 | 93 | func _get_input_port_type(port): 94 | var op: int = get_option_index(0) 95 | match op: 96 | # Dissolve 97 | 5: 98 | match port: 99 | 0: 100 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 101 | 1: 102 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 103 | 2: 104 | return VisualShaderNode.PORT_TYPE_SCALAR 105 | 3: 106 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 107 | # default 108 | _: 109 | match port: 110 | 0: 111 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 112 | 1: 113 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 114 | 2: 115 | return VisualShaderNode.PORT_TYPE_SCALAR 116 | 117 | func _get_output_port_count(): 118 | return 1 119 | 120 | func _get_output_port_name(port): 121 | return "Output" 122 | 123 | func _get_output_port_type(port): 124 | return PORT_TYPE_VECTOR_3D 125 | 126 | func _get_global_code(mode): 127 | var op: int = get_option_index(0) 128 | 129 | match op: 130 | #region Additive 131 | 0: 132 | return """ 133 | vec3 blend_additive(vec3 c1, vec3 c2, float oppacity) { 134 | return c2 + c1 * oppacity; 135 | } 136 | """ 137 | #endregion 138 | #region AddSub 139 | 1: 140 | return """ 141 | vec3 blend_addsub(vec3 c1, vec3 c2, float oppacity) { 142 | return c2 + (c1 - .5) * 2.0 * oppacity; 143 | } 144 | """ 145 | #endregion 146 | #region Burn 147 | 2: 148 | return """ 149 | float blend_burn_f(float c1, float c2) { 150 | return (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0); 151 | } 152 | 153 | vec3 blend_burn(vec3 c1, vec3 c2, float opacity) { 154 | return opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2; 155 | } 156 | """ 157 | #endregion 158 | #region Darken 159 | 3: 160 | return """ 161 | vec3 blend_darken(vec3 c1, vec3 c2, float opacity) { 162 | return opacity*min(c1, c2) + (1.0-opacity)*c2; 163 | } 164 | """ 165 | #endregion 166 | #region Difference 167 | 4: 168 | return """ 169 | vec3 blend_difference(vec3 c1, vec3 c2, float opacity) { 170 | return opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2; 171 | } 172 | """ 173 | #endregion 174 | #region Dissolve 175 | 5: 176 | return """ 177 | // 3D Noise with friendly permission by Inigo Quilez 178 | vec3 hash_noise_range( vec3 p ) { 179 | p *= mat3(vec3(127.1, 311.7, -53.7), vec3(269.5, 183.3, 77.1), vec3(-301.7, 27.3, 215.3)); 180 | return 2.0 * fract(fract(p)*4375.55) -1.; 181 | } 182 | 183 | float random_range(vec3 seed, float min, float max) { 184 | return mix(min, max, hash_noise_range(seed).x); 185 | } 186 | 187 | vec3 blend_dissolve(vec3 seed, vec3 c1, vec3 c2, float opacity) { 188 | if (random_range(vec3(seed), 0.0, 1.0) < opacity) { 189 | return c1; 190 | } else { 191 | return c2; 192 | } 193 | } 194 | """ 195 | #endregion 196 | #region Dodge 197 | 6: 198 | return """ 199 | float blend_dodge_f(float c1, float c2) { 200 | return (c1==1.0)?c1:min(c2/(1.0-c1),1.0); 201 | } 202 | 203 | vec3 blend_dodge(vec3 c1, vec3 c2, float opacity) { 204 | return opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2; 205 | } 206 | """ 207 | #endregion 208 | #region Exclusion 209 | 7: 210 | return """ 211 | float blend_exclusion_f(float c1, float c2) { 212 | return c1 + c2 - 2.0 * c1 * c2; 213 | } 214 | 215 | vec3 blend_exclusion(vec3 c1, vec3 c2, float opacity) { 216 | return opacity*vec3(blend_exclusion_f(c1.x, c2.x), blend_exclusion_f(c1.y, c2.y), blend_exclusion_f(c1.z, c2.z)) + (1.0-opacity)*c2; 217 | } 218 | """ 219 | #endregion 220 | #region GammaDark 221 | 8: 222 | return """ 223 | float blend_gamma_dark_f(float c1, float c2) 224 | { 225 | return pow(c2, (1.0 / c1)); 226 | } 227 | 228 | vec3 blend_gamma_dark(vec3 c1, vec3 c2, float opacity) 229 | { 230 | return opacity*vec3(blend_gamma_dark_f(c1.x, c2.x), blend_gamma_dark_f(c1.y, c2.y), blend_gamma_dark_f(c1.z, c2.z)) + (1.0-opacity)*c2; 231 | } 232 | """ 233 | #endregion 234 | #region GammaIllumination 235 | 9: 236 | return """ 237 | float blend_gamma_illumination_f(float c1, float c2) 238 | { 239 | return (1.0 - pow(c2, (1.0 / c1))); 240 | } 241 | 242 | vec3 blend_gamma_illumination(vec3 c1, vec3 c2, float opacity) 243 | { 244 | return opacity*vec3(blend_gamma_illumination_f(c1.x, c2.x), blend_gamma_illumination_f(c1.y, c2.y), blend_gamma_illumination_f(c1.z, c2.z)) + (1.0-opacity)*c2; 245 | } 246 | """ 247 | #endregion 248 | #region GammaLight 249 | 10: 250 | return """ 251 | float blend_gamma_light_f(float c1, float c2) 252 | { 253 | return pow(c2, c1); 254 | } 255 | 256 | vec3 blend_gamma_light(vec3 c1, vec3 c2, float opacity) 257 | { 258 | return opacity*vec3(blend_gamma_light_f(c1.x, c2.x), blend_gamma_light_f(c1.y, c2.y), blend_gamma_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; 259 | } 260 | """ 261 | #endregion 262 | #region HardLight 263 | 11: 264 | return """ 265 | float blend_overlay_f(float c1, float c2) { 266 | return (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2)); 267 | } 268 | 269 | vec3 blend_overlay(vec3 c1, vec3 c2, float opacity) { 270 | return opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2; 271 | } 272 | 273 | vec3 blend_hard_light(vec3 c1, vec3 c2, float opacity) { 274 | return opacity*0.5*(c1*c2+blend_overlay(c1, c2, 1.0)) + (1.0-opacity)*c2; 275 | } 276 | """ 277 | #endregion 278 | #region HardMix 279 | 12: 280 | return """ 281 | float blend_hard_mix_f(float c1, float c2) { 282 | return floor(c1 + c2); 283 | } 284 | 285 | vec3 blend_hard_mix(vec3 c1, vec3 c2, float opacity) { 286 | return opacity*vec3(blend_hard_mix_f(c1.x, c2.x), blend_hard_mix_f(c1.y, c2.y), blend_hard_mix_f(c1.z, c2.z)) + (1.0-opacity)*c2; 287 | } 288 | """ 289 | #endregion 290 | #region Lighten 291 | 13: 292 | return """ 293 | vec3 blend_lighten(vec3 c1, vec3 c2, float opacity) { 294 | return opacity*max(c1, c2) + (1.0-opacity)*c2; 295 | } 296 | """ 297 | #endregion 298 | #region LinearBurn 299 | 14: 300 | return """ 301 | float blend_linear_burn_f(float c1, float c2) { 302 | return 1.0- ((1.0 - c1) + (1.0 - c2)); 303 | } 304 | 305 | vec3 blend_linear_burn(vec3 c1, vec3 c2, float opacity) { 306 | return opacity*vec3(blend_linear_burn_f(c1.x, c2.x), blend_linear_burn_f(c1.y, c2.y), blend_linear_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2; 307 | } 308 | """ 309 | #endregion 310 | #region LinearLight 311 | 15: 312 | return """ 313 | float blend_linear_light_f(float c1, float c2) { 314 | return (c1 + 2.0 * c2) - 1.0; 315 | } 316 | 317 | vec3 blend_linear_light(vec3 c1, vec3 c2, float opacity) { 318 | return opacity*vec3(blend_linear_light_f(c1.x, c2.x), blend_linear_light_f(c1.y, c2.y), blend_linear_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; 319 | } 320 | """ 321 | #endregion 322 | #region Luminosity 323 | 16: 324 | return """ 325 | float blend_luminosity_f( float c1, float c2 ) 326 | { 327 | float dLum = dot(vec3(c2), vec3(0.3, 0.59, 0.11)); 328 | float sLum = dot(vec3(c1), vec3(0.3, 0.59, 0.11)); 329 | float lum = sLum - dLum; 330 | float c = c2 + lum; 331 | if(c < 0.0) return sLum + ((c - sLum) * sLum) / (sLum - c); 332 | else if(c > 1.0) return sLum + ((c - sLum) * (1.0 - sLum)) / (c - sLum); 333 | else return c; 334 | } 335 | 336 | vec3 blend_luminosity(vec3 c1, vec3 c2, float opacity) 337 | { 338 | return opacity*vec3(blend_luminosity_f(c1.x, c2.x), blend_luminosity_f(c1.y, c2.y), blend_luminosity_f(c1.z, c2.z)) + (1.0-opacity)*c2; 339 | } 340 | """ 341 | #endregion 342 | #region Multiply 343 | 17: 344 | return """ 345 | vec3 blend_multiply(vec3 c1, vec3 c2, float opacity) { 346 | return opacity*c1*c2 + (1.0-opacity)*c2; 347 | } 348 | """ 349 | #endregion 350 | #region Normal 351 | 18: 352 | return """ 353 | vec3 blend_normal(vec3 c1, vec3 c2, float opacity) { 354 | return opacity*c1 + (1.0-opacity)*c2; 355 | } 356 | """ 357 | #endregion 358 | #region Overlay 359 | 19: 360 | return """ 361 | float blend_overlay_f(float c1, float c2) { 362 | return (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2)); 363 | } 364 | 365 | vec3 blend_overlay(vec3 c1, vec3 c2, float opacity) { 366 | return opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2; 367 | } 368 | """ 369 | #endregion 370 | #region PinLight 371 | 20: 372 | return """ 373 | float blend_pin_light_f( float c1, float c2) { 374 | return (2.0 * c1 - 1.0 > c2) ? 2.0 * c1 - 1.0 : ((c1 < 0.5 * c2) ? 2.0 * c1 : c2); 375 | } 376 | 377 | vec3 blend_pin_light(vec3 c1, vec3 c2, float opacity) { 378 | return opacity*vec3(blend_pin_light_f(c1.x, c2.x), blend_pin_light_f(c1.y, c2.y), blend_pin_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; 379 | } 380 | """ 381 | #endregion 382 | #region Screen 383 | 21: 384 | return """ 385 | vec3 blend_screen(vec3 c1, vec3 c2, float opacity) { 386 | return opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2; 387 | } 388 | """ 389 | #endregion 390 | #region SoftLight 391 | 22: 392 | return """ 393 | float blend_soft_light_f(float c1, float c2) { 394 | return (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0); 395 | } 396 | 397 | vec3 blend_soft_light(vec3 c1, vec3 c2, float opacity) { 398 | return opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; 399 | } 400 | """ 401 | #endregion 402 | #region VividLight 403 | 23: 404 | return """ 405 | float blend_vivid_light_f(float c1, float c2) { 406 | return (c1 < 0.5) ? 1.0 - (1.0 - c2) / (2.0 * c1) : c2 / (2.0 * (1.0 - c1)); 407 | } 408 | 409 | vec3 blend_vivid_light(vec3 c1, vec3 c2, float opacity) { 410 | return opacity*vec3(blend_vivid_light_f(c1.x, c2.x), blend_vivid_light_f(c1.y, c2.y), blend_vivid_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; 411 | } 412 | """ 413 | #endregion 414 | 415 | 416 | func _get_code(input_vars, output_vars, mode, type): 417 | var op = get_option_index(0) 418 | match op: 419 | 0: 420 | return "%s.rgb = blend_additive(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 421 | 1: 422 | return "%s.rgb = blend_addsub(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 423 | 2: 424 | return "%s.rgb = blend_burn(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 425 | 3: 426 | return "%s.rgb = blend_darken(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 427 | 4: 428 | return "%s.rgb = blend_difference(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 429 | 5: 430 | return "%s.rgb = blend_dissolve(%s.rgb, %s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[3], input_vars[0], input_vars[1], input_vars[2]] 431 | 6: 432 | return "%s.rgb = blend_dodge(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 433 | 7: 434 | return "%s.rgb = blend_exclusion(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 435 | 8: 436 | return "%s.rgb = blend_gamma_dark(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 437 | 9: 438 | return "%s.rgb = blend_gamma_illumination(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 439 | 10: 440 | return "%s.rgb = blend_gamma_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 441 | 11: 442 | return "%s.rgb = blend_hard_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 443 | 12: 444 | return "%s.rgb = blend_hard_mix(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 445 | 13: 446 | return "%s.rgb = blend_lighten(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 447 | 14: 448 | return "%s.rgb = blend_linear_burn(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 449 | 15: 450 | return "%s.rgb = blend_linear_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 451 | 16: 452 | return "%s.rgb = blend_luminosity(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 453 | 17: 454 | return "%s.rgb = blend_multiply(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 455 | 18: 456 | return "%s.rgb = blend_normal(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 457 | 19: 458 | return "%s.rgb = blend_overlay(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 459 | 20: 460 | return "%s.rgb = blend_pin_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 461 | 21: 462 | return "%s.rgb = blend_screen(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 463 | 22: 464 | return "%s.rgb = blend_soft_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 465 | 23: 466 | return "%s.rgb = blend_vivid_light(%s.rgb, %s.rgb, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 467 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/ColorAdjustment/HSVAdjustment.gd: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). 2 | # Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | 22 | @tool 23 | extends VisualShaderNodeCustom 24 | class_name VisualShaderNodeCustomHSVAdjustment 25 | 26 | func _get_name(): 27 | return "HSVAdjustment" 28 | 29 | func _init() -> void: 30 | set_input_port_default_value(1, 0.0) 31 | set_input_port_default_value(2, 0.0) 32 | set_input_port_default_value(3, 0.0) 33 | 34 | func _get_category(): 35 | return "VisualShaderExtras/ColorAdjustment" 36 | 37 | func _get_description(): 38 | return "Convert RGB input colors to HSV and offset their values" 39 | 40 | func _get_return_icon_type(): 41 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 42 | 43 | func _get_input_port_count(): 44 | return 4 45 | 46 | func _get_input_port_name(port): 47 | match port: 48 | 0: 49 | return "RGB" 50 | 1: 51 | return "Hue Offset (Degrees)" 52 | 2: 53 | return "Saturation Offset" 54 | 3: 55 | return "Value Offset" 56 | 57 | func _get_input_port_type(port): 58 | match port: 59 | 0: 60 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 61 | 1: 62 | return VisualShaderNode.PORT_TYPE_SCALAR 63 | 2: 64 | return VisualShaderNode.PORT_TYPE_SCALAR 65 | 3: 66 | return VisualShaderNode.PORT_TYPE_SCALAR 67 | 68 | func _get_output_port_count(): 69 | return 1 70 | 71 | func _get_output_port_name(port: int) -> String: 72 | return "HSV" 73 | 74 | func _get_output_port_type(port): 75 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 76 | 77 | func _get_global_code(mode): 78 | return """ 79 | vec3 hsv_adjustment(vec3 col, float hue_offset, float sat_offset, float val_offset) { 80 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 81 | vec4 p = mix(vec4(col.bg, K.wz), vec4(col.gb, K.xy), step(col.b, col.g)); 82 | vec4 q = mix(vec4(p.xyw, col.r), vec4(col.r, p.yzx), step(p.x, col.r)); 83 | float d = q.x - min(q.w, q.y); 84 | float e = 1.0e-10; 85 | vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 86 | hsv.x += hue_offset / 360.0; 87 | hsv.y += sat_offset; 88 | hsv.z += val_offset; 89 | return hsv; 90 | } 91 | 92 | """ 93 | 94 | func _get_code(input_vars, output_vars, mode, type): 95 | return "%s = hsv_adjustment(%s.xyz, %s, %s, %s);" % [output_vars[0],input_vars[0],input_vars[1], input_vars[2], input_vars[3]] 96 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Checkerboard.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeCheckerboard 4 | 5 | func _get_name(): 6 | return "Checkerboard" 7 | 8 | func _init() -> void: 9 | set_input_port_default_value(1, Vector2(8.0, 8.0)) 10 | 11 | func _get_category(): 12 | return "VisualShaderExtras/Procedural" 13 | 14 | func _get_description(): 15 | return "Checkerboard Pattern with two given input colors" 16 | 17 | func _get_return_icon_type(): 18 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 19 | 20 | func _get_input_port_count(): 21 | return 4 22 | 23 | func _get_input_port_name(port): 24 | match port: 25 | 0: 26 | return "UV" 27 | 1: 28 | return "Tiling" 29 | 2: 30 | return "Color" 31 | 3: 32 | return "Color" 33 | 34 | func _get_input_port_type(port): 35 | match port: 36 | 0: 37 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 38 | 1: 39 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 40 | 2: 41 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 42 | 3: 43 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 44 | 45 | func _get_output_port_count(): 46 | return 1 47 | 48 | func _get_output_port_name(port: int) -> String: 49 | return "" 50 | 51 | func _get_output_port_type(port): 52 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 53 | 54 | func _get_global_code(mode): 55 | return """ 56 | vec3 checkerboard(vec2 _uv, vec2 _tiling, vec3 _color1, vec3 _color2) { 57 | float _tiling_x = floor(mod((_uv.x / (1.0 / _tiling.x)), 2.0)); 58 | float _tiling_y = floor(mod((_uv.y / (1.0 / _tiling.y)), 2.0)); 59 | bool _compare_bool = (abs(_tiling_x - _tiling_y) < 0.00001); 60 | return mix(_color1.xyz, _color2.xyz, (_compare_bool ? 1.0 : 0.0)); 61 | } 62 | """ 63 | 64 | func _get_code(input_vars, output_vars, mode, type): 65 | var uv = "UV" 66 | 67 | if input_vars[0]: 68 | uv = input_vars[0] 69 | 70 | return "%s.xyz = checkerboard(%s.xy, %s.xy, %s, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3]] 71 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/PSRD-Noise2D.gd: -------------------------------------------------------------------------------- 1 | # Copyright 2021, Stefan Gustavson and Ian MacEwan (stefan.gustavson@gmail.com, ijm567@gmail.com) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 4 | # associated documentation files (the "Software"), to deal in the Software without restriction, 5 | # including without limitation the rights to use, copy, modify, merge, publish, distribute, 6 | # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 7 | # furnished to do so, subject to the following conditions: 8 | # 9 | # The above copyright notice and this permission notice shall be included in all copies or 10 | # substantial portions of the Software. 11 | # 12 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 15 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 16 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | # SOFTWARE. 18 | 19 | # // psrdnoise (c) Stefan Gustavson and Ian McEwan, 20 | # // ver. 2021-12-02, published under the MIT license: 21 | # // https://github.com/stegu/psrdnoise/ 22 | 23 | @tool 24 | extends VisualShaderNodeCustom 25 | class_name VisualShaderNodePSRDNoise2D 26 | 27 | func _get_name(): 28 | return "PSRDNoise2D" 29 | 30 | func _init() -> void: 31 | set_input_port_default_value(0, Vector2(0.0, 0.0)) 32 | set_input_port_default_value(1, Vector2(1.0, 1.0)) 33 | set_input_port_default_value(2, 1.0) 34 | 35 | func _get_category(): 36 | return "VisualShaderExtras/Procedural" 37 | 38 | func _get_description(): 39 | return "Seamless performant 2D noise for shaders" 40 | 41 | func _get_return_icon_type(): 42 | return VisualShaderNode.PORT_TYPE_SCALAR 43 | 44 | func _get_input_port_count(): 45 | return 3 46 | 47 | func _get_input_port_name(port): 48 | match port: 49 | 0: 50 | return "Coordinates" 51 | 1: 52 | return "Period" 53 | 2: 54 | return "Alpha" 55 | 56 | func _get_input_port_type(port): 57 | match port: 58 | 0: 59 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 60 | 1: 61 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 62 | 2: 63 | return VisualShaderNode.PORT_TYPE_SCALAR 64 | 65 | func _get_output_port_count(): 66 | return 1 67 | 68 | func _get_output_port_name(port: int) -> String: 69 | return "Output" 70 | 71 | func _get_output_port_type(port): 72 | return VisualShaderNode.PORT_TYPE_SCALAR 73 | 74 | func _get_global_code(mode): 75 | return """ 76 | float psrdnoise2_with_gradient(vec2 x, vec2 period, float alpha, out vec2 gradient) { 77 | vec2 uv = vec2(x.x+x.y*0.5, x.y); 78 | vec2 i0 = floor(uv), f0 = fract(uv); 79 | float cmp = step(f0.y, f0.x); 80 | vec2 o1 = vec2(cmp, 1.0-cmp); 81 | vec2 i1 = i0 + o1, i2 = i0 + 1.0; 82 | vec2 v0 = vec2(i0.x - i0.y*0.5, i0.y); 83 | vec2 v1 = vec2(v0.x + o1.x - o1.y*0.5, v0.y + o1.y); 84 | vec2 v2 = vec2(v0.x + 0.5, v0.y + 1.0); 85 | vec2 x0 = x - v0, x1 = x - v1, x2 = x - v2; 86 | vec3 iu, iv, xw, yw; 87 | if(any(greaterThan(period, vec2(0.0)))) { 88 | xw = vec3(v0.x, v1.x, v2.x); 89 | yw = vec3(v0.y, v1.y, v2.y); 90 | if(period.x > 0.0) 91 | xw = mod(vec3(v0.x, v1.x, v2.x), period.x); 92 | if(period.y > 0.0) 93 | yw = mod(vec3(v0.y, v1.y, v2.y), period.y); 94 | iu = floor(xw + 0.5*yw + 0.5); iv = floor(yw + 0.5); 95 | } else { 96 | iu = vec3(i0.x, i1.x, i2.x); iv = vec3(i0.y, i1.y, i2.y); 97 | } 98 | vec3 hash = mod(iu, 289.0); 99 | hash = mod((hash*51.0 + 2.0)*hash + iv, 289.0); 100 | hash = mod((hash*34.0 + 10.0)*hash, 289.0); 101 | vec3 psi = hash*0.07482 + alpha; 102 | vec3 gx = cos(psi); vec3 gy = sin(psi); 103 | vec2 g0 = vec2(gx.x, gy.x); 104 | vec2 g1 = vec2(gx.y, gy.y); 105 | vec2 g2 = vec2(gx.z, gy.z); 106 | vec3 w = 0.8 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)); 107 | w = max(w, 0.0); vec3 w2 = w*w; vec3 w4 = w2*w2; 108 | vec3 gdotx = vec3(dot(g0, x0), dot(g1, x1), dot(g2, x2)); 109 | float n = dot(w4, gdotx); 110 | vec3 w3 = w2*w; vec3 dw = -8.0*w3*gdotx; 111 | vec2 dn0 = w4.x*g0 + dw.x*x0; 112 | vec2 dn1 = w4.y*g1 + dw.y*x1; 113 | vec2 dn2 = w4.z*g2 + dw.z*x2; 114 | gradient = 10.9*(dn0 + dn1 + dn2); 115 | return 10.9*n; 116 | } 117 | 118 | float psrdnoise2(vec2 x, vec2 period, float alpha) { 119 | vec2 gradient; 120 | return psrdnoise2_with_gradient(x, period, alpha, gradient); 121 | } 122 | 123 | """ 124 | 125 | func _get_code(input_vars, output_vars, mode, type): 126 | 127 | return "%s = psrdnoise2(%s.xy, %s.xy, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 128 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/PSRD-Noise3D.gd: -------------------------------------------------------------------------------- 1 | # Copyright 2021, Stefan Gustavson and Ian MacEwan (stefan.gustavson@gmail.com, ijm567@gmail.com) 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 4 | # associated documentation files (the "Software"), to deal in the Software without restriction, 5 | # including without limitation the rights to use, copy, modify, merge, publish, distribute, 6 | # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 7 | # furnished to do so, subject to the following conditions: 8 | # 9 | # The above copyright notice and this permission notice shall be included in all copies or 10 | # substantial portions of the Software. 11 | # 12 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 13 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 | # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 15 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 16 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | # SOFTWARE. 18 | 19 | # // psrdnoise (c) Stefan Gustavson and Ian McEwan, 20 | # // ver. 2021-12-02, published under the MIT license: 21 | # // https://github.com/stegu/psrdnoise/ 22 | 23 | @tool 24 | extends VisualShaderNodeCustom 25 | class_name VisualShaderNodePSRDNoise3D 26 | 27 | func _get_name(): 28 | return "PSRDNoise3D" 29 | 30 | func _init() -> void: 31 | set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0)) 32 | set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0)) 33 | set_input_port_default_value(2, 1.0) 34 | 35 | func _get_category(): 36 | return "VisualShaderExtras/Procedural" 37 | 38 | func _get_description(): 39 | return "Seamless performant 3D noise for shaders" 40 | 41 | func _get_return_icon_type(): 42 | return VisualShaderNode.PORT_TYPE_SCALAR 43 | 44 | func _get_input_port_count(): 45 | return 3 46 | 47 | func _get_input_port_name(port): 48 | match port: 49 | 0: 50 | return "Coordinates" 51 | 1: 52 | return "Period" 53 | 2: 54 | return "Alpha" 55 | 56 | func _get_input_port_type(port): 57 | match port: 58 | 0: 59 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 60 | 1: 61 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 62 | 2: 63 | return VisualShaderNode.PORT_TYPE_SCALAR 64 | 65 | func _get_output_port_count(): 66 | return 1 67 | 68 | func _get_output_port_name(port: int) -> String: 69 | return "Output" 70 | 71 | func _get_output_port_type(port): 72 | return VisualShaderNode.PORT_TYPE_SCALAR 73 | 74 | func _get_global_code(mode): 75 | return """ 76 | vec4 __psrdnoise3_permute(vec4 i) { 77 | vec4 im = mod(i, 289.0); 78 | return mod(((im*34.0)+10.0)*im, 289.0); 79 | } 80 | 81 | float psrdnoise3_with_gradient(vec3 x, vec3 period, float alpha, out vec3 gradient) { 82 | const mat3 M = mat3(vec3(0.0, 1.0, 1.0), vec3(1.0, 0.0, 1.0), vec3(1.0, 1.0, 0.0)); 83 | const mat3 Mi = mat3(vec3(-0.5, 0.5, 0.5), vec3(0.5,-0.5, 0.5), vec3(0.5, 0.5,-0.5)); 84 | vec3 uvw = M * x; 85 | vec3 i0 = floor(uvw), f0 = fract(uvw); 86 | vec3 g_ = step(f0.xyx, f0.yzz), l_ = 1.0 - g_; 87 | vec3 g = vec3(l_.z, g_.xy), l = vec3(l_.xy, g_.z); 88 | vec3 o1 = min( g, l ), o2 = max( g, l ); 89 | vec3 i1 = i0 + o1, i2 = i0 + o2, i3 = i0 + vec3(1.0); 90 | vec3 v0 = Mi * i0, v1 = Mi * i1, v2 = Mi * i2, v3 = Mi * i3; 91 | vec3 x0 = x - v0, x1 = x - v1, x2 = x - v2, x3 = x - v3; 92 | if(any(greaterThan(period, vec3(0.0)))) { 93 | vec4 vx = vec4(v0.x, v1.x, v2.x, v3.x); 94 | vec4 vy = vec4(v0.y, v1.y, v2.y, v3.y); 95 | vec4 vz = vec4(v0.z, v1.z, v2.z, v3.z); 96 | if(period.x > 0.0) vx = mod(vx, period.x); 97 | if(period.y > 0.0) vy = mod(vy, period.y); 98 | if(period.z > 0.0) vz = mod(vz, period.z); 99 | i0 = floor(M * vec3(vx.x, vy.x, vz.x) + 0.5); 100 | i1 = floor(M * vec3(vx.y, vy.y, vz.y) + 0.5); 101 | i2 = floor(M * vec3(vx.z, vy.z, vz.z) + 0.5); 102 | i3 = floor(M * vec3(vx.w, vy.w, vz.w) + 0.5); 103 | } 104 | 105 | vec4 hash = __psrdnoise3_permute( __psrdnoise3_permute( __psrdnoise3_permute( 106 | vec4(i0.z, i1.z, i2.z, i3.z )) 107 | + vec4(i0.y, i1.y, i2.y, i3.y )) 108 | + vec4(i0.x, i1.x, i2.x, i3.x )); 109 | vec4 theta = hash * 3.883222077; 110 | vec4 sz = hash * -0.006920415 + 0.996539792; 111 | vec4 psi = hash * 0.108705628; 112 | vec4 Ct = cos(theta), St = sin(theta); 113 | vec4 sz_prime = sqrt( 1.0 - sz*sz ); 114 | vec4 gx, gy, gz; 115 | if(alpha != 0.0) { 116 | vec4 px = Ct * sz_prime, py = St * sz_prime, pz = sz; 117 | vec4 Sp = sin(psi), Cp = cos(psi), Ctp = St*Sp - Ct*Cp; 118 | vec4 qx = mix( Ctp*St, Sp, sz), qy = mix(-Ctp*Ct, Cp, sz); 119 | vec4 qz = -(py*Cp + px*Sp); 120 | vec4 Sa = vec4(sin(alpha)), Ca = vec4(cos(alpha)); 121 | gx = Ca*px + Sa*qx; gy = Ca*py + Sa*qy; gz = Ca*pz + Sa*qz; 122 | } else { 123 | gx = Ct * sz_prime; gy = St * sz_prime; gz = sz; 124 | } 125 | vec3 g0 = vec3(gx.x, gy.x, gz.x), g1 = vec3(gx.y, gy.y, gz.y); 126 | vec3 g2 = vec3(gx.z, gy.z, gz.z), g3 = vec3(gx.w, gy.w, gz.w); 127 | vec4 w = 0.5-vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)); 128 | w = max(w, 0.0); vec4 w2 = w * w, w3 = w2 * w; 129 | vec4 gdotx = vec4(dot(g0,x0), dot(g1,x1), dot(g2,x2), dot(g3,x3)); 130 | float n = dot(w3, gdotx); 131 | vec4 dw = -6.0 * w2 * gdotx; 132 | vec3 dn0 = w3.x * g0 + dw.x * x0; 133 | vec3 dn1 = w3.y * g1 + dw.y * x1; 134 | vec3 dn2 = w3.z * g2 + dw.z * x2; 135 | vec3 dn3 = w3.w * g3 + dw.w * x3; 136 | gradient = 39.5 * (dn0 + dn1 + dn2 + dn3); 137 | return 39.5 * n; 138 | } 139 | 140 | float psrdnoise3(vec3 x, vec3 period, float alpha) { 141 | vec3 gradient; 142 | return psrdnoise3_with_gradient(x, period, alpha, gradient); 143 | } 144 | 145 | """ 146 | 147 | func _get_code(input_vars, output_vars, mode, type): 148 | 149 | return "%s = psrdnoise3(%s.xyz, %s.xyz, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2]] 150 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/RadialGradient.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeRadialGradient 4 | 5 | func _init(): 6 | set_input_port_default_value(1, Vector2(0.5,0.5)) 7 | set_input_port_default_value(2, 2.0) 8 | 9 | func _get_name(): 10 | return "RadialGradient" 11 | 12 | func _get_category(): 13 | return "VisualShaderExtras/Procedural" 14 | 15 | func _get_description(): 16 | return "UV Radial gradient with an adjustable fraction size" 17 | 18 | func _get_return_icon_type(): 19 | return VisualShaderNode.PORT_TYPE_SCALAR 20 | 21 | func _get_input_port_count(): 22 | return 3 23 | 24 | func _get_input_port_name(port): 25 | match port: 26 | 0: 27 | return "UV" 28 | 1: 29 | return "Offset" 30 | 2: 31 | return "Fraction size" 32 | 33 | func _get_input_port_type(port): 34 | match port: 35 | 0: 36 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 37 | 1: 38 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 39 | 2: 40 | return VisualShaderNode.PORT_TYPE_SCALAR 41 | 42 | func _get_output_port_count(): 43 | return 1 44 | 45 | func _get_output_port_name(port): 46 | return "Gradient" 47 | 48 | func _get_output_port_type(port): 49 | return VisualShaderNode.PORT_TYPE_SCALAR 50 | 51 | func _get_global_code(mode): 52 | return """ 53 | float uv_radial_gradient(vec2 uv, vec2 offset, float fraction_size) { 54 | vec2 __uv = uv - offset; 55 | float grad = atan(__uv.x, __uv.y); 56 | grad = fract(grad / (fraction_size * PI)); 57 | return grad; 58 | } 59 | """ 60 | 61 | func _get_code(input_vars, output_vars, mode, type): 62 | var uv = "UV" 63 | 64 | if input_vars[0]: 65 | uv = input_vars[0] 66 | 67 | return "%s = uv_radial_gradient(%s.xy, %s.xy, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 68 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Box.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeBox 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, Vector2(0.25, 0.25)) 26 | 27 | func _get_name(): 28 | return "SDF Box Shape" 29 | 30 | func _get_category(): 31 | return "VisualShaderExtras/Procedural" 32 | 33 | func _get_description(): 34 | return "Signed Distance Field (SDF) Box Shape" 35 | 36 | func _get_return_icon_type(): 37 | return VisualShaderNode.PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_count(): 40 | return 3 41 | 42 | func _get_input_port_name(port): 43 | match port: 44 | 0: 45 | return "UV" 46 | 1: 47 | return "Position" 48 | 2: 49 | return "Proportions" 50 | 51 | func _get_input_port_type(port): 52 | match port: 53 | 0: 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 1: 56 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 57 | 2: 58 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 59 | 60 | func _get_output_port_count(): 61 | return 1 62 | 63 | func _get_output_port_name(port): 64 | return "" 65 | 66 | func _get_output_port_type(port): 67 | return VisualShaderNode.PORT_TYPE_SCALAR 68 | 69 | func _get_global_code(mode): 70 | return """ 71 | float sdBox( in vec2 __position, in vec2 __proportions ) 72 | { 73 | vec2 __d = abs(__position) - __proportions; 74 | return length(max(__d, 0.0)) + min(max(__d.x, __d.y), 0.0); 75 | } 76 | """ 77 | 78 | func _get_code(input_vars, output_vars, mode, type): 79 | var uv = "UV" 80 | 81 | if input_vars[0]: 82 | uv = input_vars[0] 83 | 84 | return "%s = sdBox(%s.xy - %s.xy, %s.xy);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 85 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Circle.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeCircle 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, 0.25) 26 | 27 | func _get_name(): 28 | return "SDF Circle Shape" 29 | 30 | func _get_category(): 31 | return "VisualShaderExtras/Procedural" 32 | 33 | func _get_description(): 34 | return "Signed Distance Field (SDF) Circle Shape" 35 | 36 | func _get_return_icon_type(): 37 | return VisualShaderNode.PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_count(): 40 | return 3 41 | 42 | func _get_input_port_name(port): 43 | match port: 44 | 0: 45 | return "UV" 46 | 1: 47 | return "Position" 48 | 2: 49 | return "Radius" 50 | 51 | func _get_input_port_type(port): 52 | match port: 53 | 0: 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 1: 56 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 57 | 2: 58 | return VisualShaderNode.PORT_TYPE_SCALAR 59 | 60 | func _get_output_port_count(): 61 | return 1 62 | 63 | func _get_output_port_name(port): 64 | return "" 65 | 66 | func _get_output_port_type(port): 67 | return VisualShaderNode.PORT_TYPE_SCALAR 68 | 69 | func _get_global_code(mode): 70 | return """ 71 | float sdCircle(vec2 pos, float r) { 72 | return length(pos) - r; 73 | } 74 | """ 75 | 76 | func _get_code(input_vars, output_vars, mode, type): 77 | var uv = "UV" 78 | 79 | if input_vars[0]: 80 | uv = input_vars[0] 81 | 82 | return "%s = sdCircle(%s.xy - %s.xy, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 83 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/HyperbolicCross.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeHyperbolicCross 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.25)) 25 | set_input_port_default_value(2, Vector2(0.5, 0.5)) 26 | 27 | func _get_name(): 28 | return "SDF HyperBolicCross Shape" 29 | 30 | func _get_category(): 31 | return "VisualShaderExtras/Procedural" 32 | 33 | func _get_description(): 34 | return "Signed Distance Field (SDF) Hyperbolic Cross Shape" 35 | 36 | func _get_return_icon_type(): 37 | return VisualShaderNode.PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_count(): 40 | return 3 41 | 42 | func _get_input_port_name(port): 43 | match port: 44 | 0: 45 | return "UV" 46 | 1: 47 | return "Position" 48 | 2: 49 | return "Proportions" 50 | 51 | func _get_input_port_type(port): 52 | match port: 53 | 0: 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 1: 56 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 57 | 2: 58 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 59 | 60 | func _get_output_port_count(): 61 | return 1 62 | 63 | func _get_output_port_name(port): 64 | return "" 65 | 66 | func _get_output_port_type(port): 67 | return VisualShaderNode.PORT_TYPE_SCALAR 68 | 69 | func _get_global_code(mode): 70 | return """ 71 | float sdHyperbolicCross( in vec2 p, in vec2 __prop) 72 | { 73 | vec2 result = pow(abs(p), __prop); 74 | return 1.0 - (result.x + result.y); 75 | } 76 | """ 77 | 78 | func _get_code(input_vars, output_vars, mode, type): 79 | var uv = "UV" 80 | 81 | if input_vars[0]: 82 | uv = input_vars[0] 83 | 84 | return "%s = sdHyperbolicCross(%s.xy - %s.xy, %s.xy);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 85 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Parallelogram.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeParallelogram 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, 0.15) 26 | set_input_port_default_value(3, 0.3) 27 | set_input_port_default_value(4, 0.2) 28 | 29 | func _get_name(): 30 | return "SDF Parallelogram Shape" 31 | 32 | func _get_category(): 33 | return "VisualShaderExtras/Procedural" 34 | 35 | func _get_description(): 36 | return "Signed Distance Field (SDF) Parallelogram Shape" 37 | 38 | func _get_return_icon_type(): 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 41 | func _get_input_port_count(): 42 | return 5 43 | 44 | func _get_input_port_name(port): 45 | match port: 46 | 0: 47 | return "UV" 48 | 1: 49 | return "Position" 50 | 2: 51 | return "Width" 52 | 3: 53 | return "Height" 54 | 4: 55 | return "Skew" 56 | 57 | func _get_input_port_type(port): 58 | match port: 59 | 0: 60 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 61 | 1: 62 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 63 | 2: 64 | return VisualShaderNode.PORT_TYPE_SCALAR 65 | 3: 66 | return VisualShaderNode.PORT_TYPE_SCALAR 67 | 4: 68 | return VisualShaderNode.PORT_TYPE_SCALAR 69 | 70 | func _get_output_port_count(): 71 | return 1 72 | 73 | func _get_output_port_name(port): 74 | return "" 75 | 76 | func _get_output_port_type(port): 77 | return VisualShaderNode.PORT_TYPE_SCALAR 78 | 79 | func _get_global_code(mode): 80 | return """ 81 | float sdParallelogram( in vec2 p, float wi, float he, float sk ) 82 | { 83 | vec2 e = vec2(sk,he); 84 | p = (p.y<0.0)?-p:p; 85 | vec2 w = p - e; w.x -= clamp(w.x,-wi,wi); 86 | vec2 d = vec2(dot(w,w), -w.y); 87 | float s = p.x*e.y - p.y*e.x; 88 | p = (s<0.0)?-p:p; 89 | vec2 v = p - vec2(wi,0); v -= e*clamp(dot(v,e)/dot(e,e),-1.0,1.0); 90 | d = min( d, vec2(dot(v,v), wi*he-abs(s))); 91 | return sqrt(d.x)*sign(-d.y); 92 | } 93 | """ 94 | 95 | func _get_code(input_vars, output_vars, mode, type): 96 | var uv = "UV" 97 | 98 | if input_vars[0]: 99 | uv = input_vars[0] 100 | 101 | return "%s = sdParallelogram(%s.xy - %s.xy, %s, %s, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3], input_vars[4]] 102 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/PreciseBox.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodePreciseBox 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, Vector2(-0.25, -0.25)) 26 | set_input_port_default_value(3, Vector2(0.25, 0.25)) 27 | set_input_port_default_value(4, 0.2) 28 | 29 | func _get_name(): 30 | return "SDF PreciseBox Shape" 31 | 32 | func _get_category(): 33 | return "VisualShaderExtras/Procedural" 34 | 35 | func _get_description(): 36 | return "Signed Distance Field (SDF) Precise Box Shape" 37 | 38 | func _get_return_icon_type(): 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 41 | func _get_input_port_count(): 42 | return 5 43 | 44 | func _get_input_port_name(port): 45 | match port: 46 | 0: 47 | return "UV" 48 | 1: 49 | return "Position" 50 | 2: 51 | return "Point A" 52 | 3: 53 | return "Point B" 54 | 4: 55 | return "Thickness" 56 | 57 | func _get_input_port_type(port): 58 | match port: 59 | 0: 60 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 61 | 1: 62 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 63 | 2: 64 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 65 | 3: 66 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 67 | 4: 68 | return VisualShaderNode.PORT_TYPE_SCALAR 69 | 70 | func _get_output_port_count(): 71 | return 1 72 | 73 | func _get_output_port_name(port): 74 | return "" 75 | 76 | func _get_output_port_type(port): 77 | return VisualShaderNode.PORT_TYPE_SCALAR 78 | 79 | func _get_global_code(mode): 80 | return """ 81 | float sdPreciseBox( in vec2 p, in vec2 a, in vec2 b, float th ) 82 | { 83 | float l = length(b-a); 84 | vec2 d = (b-a)/l; 85 | vec2 q = (p-(a+b)*0.5); 86 | q = mat2(vec2(d.x,-d.y), vec2(d.y,d.x))*q; 87 | q = abs(q)-vec2(l,th)*0.5; 88 | return length(max(q,0.0)) + min(max(q.x,q.y),0.0); 89 | } 90 | """ 91 | 92 | func _get_code(input_vars, output_vars, mode, type): 93 | var uv = "UV" 94 | 95 | if input_vars[0]: 96 | uv = input_vars[0] 97 | 98 | return "%s = sdPreciseBox(%s.xy - %s.xy, %s.xy, %s.xy, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3], input_vars[4]] 99 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/PreciseHyperbolicCross.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodePreciseHyperbolicCross 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.25)) 25 | set_input_port_default_value(2, Vector2(0.5, 0.5)) 26 | set_input_port_default_value(3, 0.13) 27 | 28 | func _get_name(): 29 | return "SDF PreciseHyperBolicCross Shape" 30 | 31 | func _get_category(): 32 | return "VisualShaderExtras/Procedural" 33 | 34 | func _get_description(): 35 | return "Signed Distance Field (SDF) Precise Hyperbolic Cross Shape" 36 | 37 | func _get_return_icon_type(): 38 | return VisualShaderNode.PORT_TYPE_SCALAR 39 | 40 | func _get_input_port_count(): 41 | return 4 42 | 43 | func _get_input_port_name(port): 44 | match port: 45 | 0: 46 | return "UV" 47 | 1: 48 | return "Position" 49 | 2: 50 | return "Proportions" 51 | 3: 52 | return "Size" 53 | 54 | func _get_input_port_type(port): 55 | match port: 56 | 0: 57 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 58 | 1: 59 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 60 | 2: 61 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 62 | 3: 63 | return VisualShaderNode.PORT_TYPE_SCALAR 64 | 65 | func _get_output_port_count(): 66 | return 1 67 | 68 | func _get_output_port_name(port): 69 | return "" 70 | 71 | func _get_output_port_type(port): 72 | return VisualShaderNode.PORT_TYPE_SCALAR 73 | 74 | func _get_global_code(mode): 75 | return """ 76 | float sdPreciseHyperbolicCross( in vec2 p, float k ) 77 | { 78 | // scale 79 | float s = 1.0/k - k; 80 | p = p*s; 81 | // symmetry 82 | p = abs(p); 83 | p = (p.x>p.y) ? p.yx : p.xy; 84 | // offset 85 | p += k; 86 | 87 | // solve quartic (for details see https://www.shadertoy.com/view/ftcyW8) 88 | float x2 = p.x*p.x/16.0; 89 | float y2 = p.y*p.y/16.0; 90 | float r = (p.x*p.y-4.0)/12.0; 91 | float q = y2-x2; 92 | float h = q*q-r*r*r; 93 | float u; 94 | if( h<0.0 ) 95 | { 96 | float m = sqrt(r); 97 | u = m*cos( acos(q/(r*m) )/3.0 ); 98 | } 99 | else 100 | { 101 | float m = pow(sqrt(h)+q,1.0/3.0); 102 | u = (m+r/m)/2.0; 103 | } 104 | float w = sqrt(u+x2); 105 | float x = p.x/4.0-w+sqrt(2.0*x2-u+(p.y-x2*p.x*2.0)/w/4.0); 106 | 107 | // clamp arm 108 | x = max(x,k); 109 | 110 | // compute distance to closest point 111 | float d = length( p-vec2(x,1.0/x) ) / s; 112 | 113 | // sign 114 | return p.x*p.y < 1.0 ? -d : d; 115 | } 116 | """ 117 | 118 | func _get_code(input_vars, output_vars, mode, type): 119 | var uv = "UV" 120 | 121 | if input_vars[0]: 122 | uv = input_vars[0] 123 | 124 | return "%s = sdPreciseHyperbolicCross((%s.xy - %s.xy)*(2.0-%s.xy), %s);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3]] 125 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Rhombus.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeRhombus 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, Vector2(0.25, 0.25)) 26 | 27 | func _get_name(): 28 | return "SDF Rhombus Shape" 29 | 30 | func _get_category(): 31 | return "VisualShaderExtras/Procedural" 32 | 33 | func _get_description(): 34 | return "Signed Distance Field (SDF) Rhombus Shape" 35 | 36 | func _get_return_icon_type(): 37 | return VisualShaderNode.PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_count(): 40 | return 3 41 | 42 | func _get_input_port_name(port): 43 | match port: 44 | 0: 45 | return "UV" 46 | 1: 47 | return "Position" 48 | 2: 49 | return "Proportions" 50 | 51 | func _get_input_port_type(port): 52 | match port: 53 | 0: 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 1: 56 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 57 | 2: 58 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 59 | 60 | func _get_output_port_count(): 61 | return 1 62 | 63 | func _get_output_port_name(port): 64 | return "" 65 | 66 | func _get_output_port_type(port): 67 | return VisualShaderNode.PORT_TYPE_SCALAR 68 | 69 | func _get_global_code(mode): 70 | return """ 71 | float ndot(vec2 a, vec2 b ) { return a.x*b.x - a.y*b.y; } 72 | float sdRhombus( in vec2 p, in vec2 b ) 73 | { 74 | p = abs(p); 75 | float h = clamp( ndot(b-2.0*p,b)/dot(b,b), -1.0, 1.0 ); 76 | float d = length( p-0.5*b*vec2(1.0-h,1.0+h) ); 77 | return d * sign( p.x*b.y + p.y*b.x - b.x*b.y ); 78 | } 79 | """ 80 | 81 | func _get_code(input_vars, output_vars, mode, type): 82 | var uv = "UV" 83 | 84 | if input_vars[0]: 85 | uv = input_vars[0] 86 | 87 | return "%s = sdRhombus(%s.xy - %s.xy, %s.xy);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 88 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/RoundedBox.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeRoundedBox 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, Vector2(0.25, 0.25)) 26 | set_input_port_default_value(3, Vector4(0.0, 0.0, 0.0, 0.0)) 27 | 28 | func _get_name(): 29 | return "SDF RoundedBox Shape" 30 | 31 | func _get_category(): 32 | return "VisualShaderExtras/Procedural" 33 | 34 | func _get_description(): 35 | return "Signed Distance Field (SDF) Rounded Box Shape" 36 | 37 | func _get_return_icon_type(): 38 | return VisualShaderNode.PORT_TYPE_SCALAR 39 | 40 | func _get_input_port_count(): 41 | return 4 42 | 43 | func _get_input_port_name(port): 44 | match port: 45 | 0: 46 | return "UV" 47 | 1: 48 | return "Position" 49 | 2: 50 | return "Proportions" 51 | 3: 52 | return "Radia" 53 | 54 | func _get_input_port_type(port): 55 | match port: 56 | 0: 57 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 58 | 1: 59 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 60 | 2: 61 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 62 | 3: 63 | return VisualShaderNode.PORT_TYPE_VECTOR_4D 64 | 65 | func _get_output_port_count(): 66 | return 1 67 | 68 | func _get_output_port_name(port): 69 | return "" 70 | 71 | func _get_output_port_type(port): 72 | return VisualShaderNode.PORT_TYPE_SCALAR 73 | 74 | func _get_global_code(mode): 75 | return """ 76 | float sdRoundedBox( in vec2 __pos, in vec2 __proportions, in vec4 __radia ) 77 | { 78 | __radia.xy = (__pos.x > 0.0) ? __radia.xy : vec2(__radia.w, __radia.z); 79 | __radia.x = (__pos.y > 0.0) ? __radia.x : __radia.y; 80 | vec2 __q = abs(__pos) - __proportions + __radia.x; 81 | return min(max(__q.x, __q.y), 0.0) + length(max(__q, 0.0)) - __radia.x; 82 | } 83 | """ 84 | 85 | func _get_code(input_vars, output_vars, mode, type): 86 | var uv = "UV" 87 | 88 | if input_vars[0]: 89 | uv = input_vars[0] 90 | 91 | return "%s = sdRoundedBox(%s.xy - %s.xy, %s.xy, %s.xyzw);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3]] 92 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Trapezoid.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeTrapezoid 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.5)) 25 | set_input_port_default_value(2, 0.15) 26 | set_input_port_default_value(3, 0.35) 27 | set_input_port_default_value(4, 0.25) 28 | 29 | func _get_name(): 30 | return "SDF Trapezoid Shape" 31 | 32 | func _get_category(): 33 | return "VisualShaderExtras/Procedural" 34 | 35 | func _get_description(): 36 | return "Signed Distance Field (SDF) Trapezoid Shape" 37 | 38 | func _get_return_icon_type(): 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 41 | func _get_input_port_count(): 42 | return 5 43 | 44 | func _get_input_port_name(port): 45 | match port: 46 | 0: 47 | return "UV" 48 | 1: 49 | return "Position" 50 | 2: 51 | return "Top width" 52 | 3: 53 | return "Bottom width" 54 | 4: 55 | return "height" 56 | 57 | func _get_input_port_type(port): 58 | match port: 59 | 0: 60 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 61 | 1: 62 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 63 | 2: 64 | return VisualShaderNode.PORT_TYPE_SCALAR 65 | 3: 66 | return VisualShaderNode.PORT_TYPE_SCALAR 67 | 4: 68 | return VisualShaderNode.PORT_TYPE_SCALAR 69 | 70 | func _get_output_port_count(): 71 | return 1 72 | 73 | func _get_output_port_name(port): 74 | return "" 75 | 76 | func _get_output_port_type(port): 77 | return VisualShaderNode.PORT_TYPE_SCALAR 78 | 79 | func _get_global_code(mode): 80 | return """ 81 | float sdTrapezoid( in vec2 p, in float r1, float r2, float he ) 82 | { 83 | vec2 k1 = vec2(r2,he); 84 | vec2 k2 = vec2(r2-r1,2.0*he); 85 | p.x = abs(p.x); 86 | vec2 ca = vec2(p.x-min(p.x,(p.y<0.0)?r1:r2), abs(p.y)-he); 87 | vec2 cb = p - k1 + k2*clamp( dot(k1-p,k2)/dot(k2, k2), 0.0, 1.0 ); 88 | float s = (cb.x<0.0 && ca.y<0.0) ? -1.0 : 1.0; 89 | return s*sqrt( min(dot(ca, ca),dot(cb, cb)) ); 90 | } 91 | """ 92 | 93 | func _get_code(input_vars, output_vars, mode, type): 94 | var uv = "UV" 95 | 96 | if input_vars[0]: 97 | uv = input_vars[0] 98 | 99 | return "%s = sdTrapezoid(%s.xy - %s.xy, %s, %s, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3], input_vars[4]] 100 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Procedural/Shapes/Triangle.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | @tool 20 | extends VisualShaderNodeCustom 21 | class_name VisualShaderNodeTriangle 22 | 23 | func _init(): 24 | set_input_port_default_value(1, Vector2(0.5, 0.25)) 25 | set_input_port_default_value(2, Vector2(0.25, 0.5)) 26 | 27 | func _get_name(): 28 | return "SDF Triangle Shape" 29 | 30 | func _get_category(): 31 | return "VisualShaderExtras/Procedural" 32 | 33 | func _get_description(): 34 | return "Signed Distance Field (SDF) Triangle Shape" 35 | 36 | func _get_return_icon_type(): 37 | return VisualShaderNode.PORT_TYPE_SCALAR 38 | 39 | func _get_input_port_count(): 40 | return 3 41 | 42 | func _get_input_port_name(port): 43 | match port: 44 | 0: 45 | return "UV" 46 | 1: 47 | return "Position" 48 | 2: 49 | return "Proportions" 50 | 51 | func _get_input_port_type(port): 52 | match port: 53 | 0: 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 1: 56 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 57 | 2: 58 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 59 | 60 | func _get_output_port_count(): 61 | return 1 62 | 63 | func _get_output_port_name(port): 64 | return "" 65 | 66 | func _get_output_port_type(port): 67 | return VisualShaderNode.PORT_TYPE_SCALAR 68 | 69 | func _get_global_code(mode): 70 | return """ 71 | float sdTriangleIsosceles( in vec2 p, in vec2 q ) 72 | { 73 | p.x = abs(p.x); 74 | vec2 a = p - q*clamp( dot(p,q)/dot(q,q), 0.0, 1.0 ); 75 | vec2 b = p - q*vec2( clamp( p.x/q.x, 0.0, 1.0 ), 1.0 ); 76 | float s = -sign( q.y ); 77 | vec2 d = min( vec2( dot(a,a), s*(p.x*q.y-p.y*q.x) ), 78 | vec2( dot(b,b), s*(p.y-q.y) )); 79 | return -sqrt(d.x)*sign(d.y); 80 | } 81 | """ 82 | 83 | func _get_code(input_vars, output_vars, mode, type): 84 | var uv = "UV" 85 | 86 | if input_vars[0]: 87 | uv = input_vars[0] 88 | 89 | return "%s = sdTriangleIsosceles(%s.xy - %s.xy, %s.xy);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 90 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/UV/UVFlipbook.gd: -------------------------------------------------------------------------------- 1 | # from https://github.com/thnewlands/unity-surfaceshader-flipbook 2 | # 3 | # MIT License 4 | # 5 | # Copyright (c) 2017 Thomas Newlands 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | @tool 26 | extends VisualShaderNodeCustom 27 | class_name VisualShaderNodeUVFlipbook 28 | 29 | func _init(): 30 | set_input_port_default_value(1, 1) 31 | set_input_port_default_value(2, 1) 32 | set_input_port_default_value(3, 0) 33 | set_input_port_default_value(4, 1) 34 | set_input_port_default_value(5, 0.3) 35 | 36 | func _get_name(): 37 | return "UVFlipbook" 38 | 39 | func _get_category(): 40 | return "VisualShaderExtras/UV" 41 | 42 | func _get_description(): 43 | return "UV Flipbook Animation" 44 | 45 | func _get_return_icon_type(): 46 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 47 | 48 | func _get_input_port_count(): 49 | return 6 50 | 51 | func _get_input_port_name(port): 52 | match port: 53 | 0: 54 | return "UV" 55 | 1: 56 | return "Columns" 57 | 2: 58 | return "Rows" 59 | 3: 60 | return "Starting frame" 61 | 4: 62 | return "Ending frame" 63 | 5: 64 | return "Animation speed" 65 | 66 | func _get_input_port_type(port): 67 | match port: 68 | 0: 69 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 70 | 1: 71 | return VisualShaderNode.PORT_TYPE_SCALAR_INT 72 | 2: 73 | return VisualShaderNode.PORT_TYPE_SCALAR_INT 74 | 3: 75 | return VisualShaderNode.PORT_TYPE_SCALAR_INT 76 | 4: 77 | return VisualShaderNode.PORT_TYPE_SCALAR_INT 78 | 5: 79 | return VisualShaderNode.PORT_TYPE_SCALAR 80 | 81 | func _get_output_port_count(): 82 | return 1 83 | 84 | func _get_output_port_name(port): 85 | return "UV" 86 | 87 | func _get_output_port_type(port): 88 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 89 | 90 | func _get_global_code(mode): 91 | return """ 92 | vec2 flipbook_anim(vec2 __uv, int __columns, int __rows, int __starting_frame, int __ending_frame, float __anim_speed) { 93 | __starting_frame += int(fract(TIME * __anim_speed) * float(__ending_frame)); 94 | float frame = float(clamp(__starting_frame, 0, __ending_frame)); 95 | vec2 offPerFrame = vec2((1.0 / float(__columns)), (1.0 / float(__rows))); 96 | 97 | vec2 sprite_size = vec2(__uv.x / float(__columns), __uv.y / float(__rows)); 98 | vec2 current_sprite = vec2(0.0, 1.0 - offPerFrame.y); 99 | current_sprite.x += frame * offPerFrame.x; 100 | float rowIndex; 101 | float _mod = modf(frame / float(__columns), rowIndex); 102 | current_sprite.y -= rowIndex * offPerFrame.y; 103 | current_sprite.x -= rowIndex * float(__columns) * offPerFrame.x; 104 | 105 | vec2 sprite_uv = (sprite_size + current_sprite); 106 | 107 | return sprite_uv; 108 | } 109 | """ 110 | 111 | func _get_code(input_vars, output_vars, mode, type): 112 | var uv = "UV" 113 | 114 | if input_vars[0]: 115 | uv = input_vars[0] 116 | 117 | return "%s.xy = flipbook_anim(%s.xy, %s, %s, %s, %s, %s );" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3], input_vars[4], input_vars[5]] 118 | 119 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/UV/UVRotate.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeUVRotate 4 | 5 | func _init(): 6 | set_input_port_default_value(1, Vector2(0.5,0.5)) 7 | set_input_port_default_value(2, 10.0) 8 | 9 | func _get_name(): 10 | return "UVRotate" 11 | 12 | func _get_category(): 13 | return "VisualShaderExtras/UV" 14 | 15 | func _get_description(): 16 | return "UV Rotate" 17 | 18 | func _get_return_icon_type(): 19 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 20 | 21 | func _get_input_port_count(): 22 | return 3 23 | 24 | func _get_input_port_name(port): 25 | match port: 26 | 0: 27 | return "UV" 28 | 1: 29 | return "Pivot" 30 | 2: 31 | return "Angle (Radians)" 32 | 33 | func _get_input_port_type(port): 34 | match port: 35 | 0: 36 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 37 | 1: 38 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 39 | 2: 40 | return VisualShaderNode.PORT_TYPE_SCALAR 41 | 42 | func _get_output_port_count(): 43 | return 1 44 | 45 | func _get_output_port_name(port): 46 | return "UV" 47 | 48 | func _get_output_port_type(port): 49 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 50 | 51 | func _get_global_code(mode): 52 | return """ 53 | vec2 uv_rotate(vec2 uv, vec2 pivot, float angle) { 54 | mat2 rotation = mat2(vec2(sin(angle), -cos(angle)), vec2(cos(angle), sin(angle))); 55 | uv -= pivot; 56 | uv = uv * rotation; 57 | uv += pivot; 58 | return uv; 59 | } 60 | """ 61 | 62 | func _get_code(input_vars, output_vars, mode, type): 63 | var uv = "UV" 64 | 65 | if input_vars[0]: 66 | uv = input_vars[0] 67 | 68 | return "%s.xy = uv_rotate(%s.xy, %s.xy, %s);" % [output_vars[0], uv, input_vars[1], input_vars[2]] 69 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/UV/UVTiler.gd: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # Copyright © 2022 Inigo Quilez 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # The above copyright notice and this permission notice shall be included 10 | # in all copies or substantial portions of the Software. 11 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 14 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 16 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 17 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | # With assist from https://thebookofshaders.com/09/ 20 | 21 | @tool 22 | extends VisualShaderNodeCustom 23 | class_name VisualShaderNodeTiler 24 | 25 | func _get_name(): 26 | return "UVTiler" 27 | 28 | func _init() -> void: 29 | set_input_port_default_value(0, Vector2(2, 2)) 30 | set_input_port_default_value(1, 4.0) 31 | set_input_port_default_value(2, 0.0) 32 | 33 | func _get_category(): 34 | return "VisualShaderExtras/UV" 35 | 36 | func _get_description(): 37 | return "Tile a given UV into the given UV tiles and rotate them" 38 | 39 | func _get_return_icon_type(): 40 | return VisualShaderNode.PORT_TYPE_VECTOR_4D 41 | 42 | func _get_input_port_count(): 43 | return 3 44 | 45 | func _get_input_port_name(port): 46 | match port: 47 | 0: 48 | return "Tiling" 49 | 1: 50 | return "Split" 51 | 2: 52 | return "Rotation (Radians)" 53 | 54 | func _get_input_port_type(port): 55 | match port: 56 | 0: 57 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 58 | 1: 59 | return VisualShaderNode.PORT_TYPE_SCALAR 60 | 2: 61 | return VisualShaderNode.PORT_TYPE_SCALAR 62 | 63 | func _get_output_port_count(): 64 | return 1 65 | 66 | func _get_output_port_name(port: int) -> String: 67 | return "UV" 68 | 69 | func _get_output_port_type(port): 70 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 71 | 72 | func _get_global_code(mode): 73 | return """ 74 | vec2 tile(vec2 _uv, float _zoom){ 75 | _uv *= _zoom; 76 | return fract(_uv); 77 | } 78 | 79 | vec2 rotate(vec2 _uv, float _angle) { 80 | _uv -= 0.5; 81 | _uv = mat2( vec2(cos(_angle), -sin(_angle)), vec2(sin(_angle), cos(_angle)) ) * _uv; 82 | _uv += 0.5; 83 | return _uv; 84 | } 85 | """ 86 | 87 | func _get_code(input_vars, output_vars, mode, type): 88 | var rot:String 89 | rot = "st = rotate(st, %s);" % input_vars[2] if input_vars[2] != "" else "" 90 | 91 | return """ 92 | vec2 st = UV.xy/{in_tilexy}.xy; 93 | st = tile(st,{split}); 94 | {rot} 95 | {out_uv} = st; 96 | """.format( 97 | { 98 | "in_tilexy":input_vars[0], 99 | "split": input_vars[1], 100 | "out_uv": output_vars[0], 101 | "rot": rot 102 | }) 103 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/UV/UVTwirl.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeUVTwirl 4 | 5 | func _init(): 6 | set_input_port_default_value(1, Vector2(0.5,0.5)) 7 | set_input_port_default_value(2, 10.0) 8 | set_input_port_default_value(3, Vector2(0,0)) 9 | 10 | func _get_name(): 11 | return "UVTwirl" 12 | 13 | func _get_category(): 14 | return "VisualShaderExtras/UV" 15 | 16 | func _get_description(): 17 | return "UV Twirl" 18 | 19 | func _get_return_icon_type(): 20 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 21 | 22 | func _get_input_port_count(): 23 | return 4 24 | 25 | func _get_input_port_name(port): 26 | match port: 27 | 0: 28 | return "UV" 29 | 1: 30 | return "Center" 31 | 2: 32 | return "Strength" 33 | 3: 34 | return "Offset" 35 | 36 | func _get_input_port_type(port): 37 | match port: 38 | 0: 39 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 40 | 1: 41 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 42 | 2: 43 | return VisualShaderNode.PORT_TYPE_SCALAR 44 | 3: 45 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 46 | 47 | func _get_output_port_count(): 48 | return 1 49 | 50 | func _get_output_port_name(port): 51 | return "UV" 52 | 53 | func _get_output_port_type(port): 54 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 55 | 56 | func _get_global_code(mode): 57 | return """ 58 | vec2 Twirl(vec2 __uv, vec2 __center, float __strength, vec2 __offset) 59 | { 60 | vec2 __delta = __uv - __center; 61 | float __angle = __strength * length(__delta); 62 | float __x = cos(__angle) * __delta.x - sin(__angle) * __delta.y; 63 | float __y = sin(__angle) * __delta.x + cos(__angle) * __delta.y; 64 | return vec2(__x + __center.x + __offset.x, __y + __center.y + __offset.y); 65 | } 66 | """ 67 | 68 | func _get_code(input_vars, output_vars, mode, type): 69 | var uv = "UV" 70 | 71 | if input_vars[0]: 72 | uv = input_vars[0] 73 | 74 | return "%s.xy = Twirl(%s.xy, %s.xy, %s, %s.xy);" % [output_vars[0], uv, input_vars[1], input_vars[2], input_vars[3]] 75 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/UV/UVtoSphereCoord.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeUVtoSphereCoord 4 | 5 | func _get_name(): 6 | return "UVtoSphereCoord" 7 | 8 | func _init() -> void: 9 | set_input_port_default_value(1, Vector3(0.0, 0.0, 0.0)) 10 | 11 | func _get_category(): 12 | return "VisualShaderExtras/UV" 13 | 14 | func _get_description(): 15 | return "UV to Sphere Coord" 16 | 17 | func _get_return_icon_type(): 18 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 19 | 20 | func _get_input_port_count(): 21 | return 2 22 | 23 | func _get_input_port_name(port): 24 | match port: 25 | 0: 26 | return "Sphere Surface Point" 27 | 1: 28 | return "Sphere Center" 29 | 30 | func _get_input_port_type(port): 31 | match port: 32 | 0: 33 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 34 | 1: 35 | return VisualShaderNode.PORT_TYPE_VECTOR_3D 36 | 37 | func _get_output_port_count(): 38 | return 1 39 | 40 | func _get_output_port_name(port): 41 | return "UV" 42 | 43 | func _get_output_port_type(port): 44 | return VisualShaderNode.PORT_TYPE_VECTOR_2D 45 | 46 | func _get_global_code(mode): 47 | return """ 48 | vec2 uv_to_sphere_coord(vec3 sphere_surface_point, vec3 sphere_center) 49 | { 50 | vec3 n = normalize(sphere_surface_point - sphere_center); 51 | float sphere_u = atan(n.x, n.z) / (2.0*PI) + 0.5; 52 | float sphere_v = n.y * 0.5 + 0.5; 53 | return vec2(sphere_u, sphere_v); 54 | } 55 | """ 56 | 57 | func _get_code(input_vars, output_vars, mode, type): 58 | return "%s.xy = uv_to_sphere_coord(%s.xyz, %s.xyz);" % [output_vars[0], input_vars[0], input_vars[1]] 59 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Wave/SawtoothWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeSawtoothWave 4 | 5 | func _init(): 6 | set_input_port_default_value(1, 1.0) 7 | set_input_port_default_value(2, 1.0) 8 | set_input_port_default_value(3, 0.0) 9 | 10 | func _get_name(): 11 | return "SawtoothWave" 12 | 13 | func _get_category(): 14 | return "VisualShaderExtras/Wave" 15 | 16 | func _get_description(): 17 | return "Sawtooth Wave function" 18 | 19 | func _get_return_icon_type(): 20 | return VisualShaderNode.PORT_TYPE_SCALAR 21 | 22 | func _get_input_port_count(): 23 | return 4 24 | 25 | func _get_input_port_name(port): 26 | match port: 27 | 0: 28 | return "IN" 29 | 1: 30 | return "Amplitude" 31 | 2: 32 | return "Frequency" 33 | 3: 34 | return "Height" 35 | 36 | func _get_input_port_type(port): 37 | match port: 38 | 0: 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 1: 41 | return VisualShaderNode.PORT_TYPE_SCALAR 42 | 2: 43 | return VisualShaderNode.PORT_TYPE_SCALAR 44 | 3: 45 | return VisualShaderNode.PORT_TYPE_SCALAR 46 | 47 | func _get_output_port_count(): 48 | return 1 49 | 50 | func _get_output_port_name(port): 51 | return "" 52 | 53 | func _get_output_port_type(port): 54 | return VisualShaderNode.PORT_TYPE_SCALAR 55 | 56 | func _get_global_code(mode): 57 | return """ 58 | float sawtooth_wave(float IN, float __amplitude, float __period, float __height) { 59 | return 2.0 * __amplitude * ((IN/__period) - floor((1.0/2.0) + (IN / __period))) + __height; 60 | } 61 | """ 62 | 63 | func _get_code(input_vars, output_vars, mode, type): 64 | 65 | return "%s = sawtooth_wave(%s, %s, %s, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2], input_vars[3]] 66 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Wave/SineWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeSineWave 4 | 5 | func _init(): 6 | set_input_port_default_value(1, 1.0) 7 | set_input_port_default_value(2, 1.0) 8 | set_input_port_default_value(3, 0.0) 9 | set_input_port_default_value(4, 0.0) 10 | 11 | func _get_name(): 12 | return "SineWave" 13 | 14 | func _get_category(): 15 | return "VisualShaderExtras/Wave" 16 | 17 | func _get_description(): 18 | return "Sine Wave function" 19 | 20 | func _get_return_icon_type(): 21 | return VisualShaderNode.PORT_TYPE_SCALAR 22 | 23 | func _get_input_port_count(): 24 | return 5 25 | 26 | func _get_input_port_name(port): 27 | match port: 28 | 0: 29 | return "IN" 30 | 1: 31 | return "Amplitude" 32 | 2: 33 | return "Frequency" 34 | 3: 35 | return "Phase" 36 | 4: 37 | return "Height" 38 | 39 | func _get_input_port_type(port): 40 | match port: 41 | 0: 42 | return VisualShaderNode.PORT_TYPE_SCALAR 43 | 1: 44 | return VisualShaderNode.PORT_TYPE_SCALAR 45 | 2: 46 | return VisualShaderNode.PORT_TYPE_SCALAR 47 | 3: 48 | return VisualShaderNode.PORT_TYPE_SCALAR 49 | 4: 50 | return VisualShaderNode.PORT_TYPE_SCALAR 51 | 52 | func _get_output_port_count(): 53 | return 1 54 | 55 | func _get_output_port_name(port): 56 | return "" 57 | 58 | func _get_output_port_type(port): 59 | return VisualShaderNode.PORT_TYPE_SCALAR 60 | 61 | func _get_global_code(mode): 62 | return """ 63 | float sine_wave(float IN, float __amplitude, float __frequency, float __phase, float __height) { 64 | return __amplitude * sin(2.0 * PI * __frequency * IN + __phase) + __height; 65 | } 66 | """ 67 | 68 | func _get_code(input_vars, output_vars, mode, type): 69 | 70 | return "%s = sine_wave(%s, %s, %s, %s, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2], input_vars[3], input_vars[4]] 71 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Wave/SineWaveAngular.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeSineWaveAngular 4 | 5 | func _init(): 6 | set_input_port_default_value(1, 1.0) 7 | set_input_port_default_value(2, 6.0) 8 | set_input_port_default_value(3, 0.0) 9 | set_input_port_default_value(4, 0.0) 10 | 11 | func _get_name(): 12 | return "SineWaveAngular" 13 | 14 | func _get_category(): 15 | return "VisualShaderExtras/Wave" 16 | 17 | func _get_description(): 18 | return "Sine Wave function with angular frequency input" 19 | 20 | func _get_return_icon_type(): 21 | return VisualShaderNode.PORT_TYPE_SCALAR 22 | 23 | func _get_input_port_count(): 24 | return 5 25 | 26 | func _get_input_port_name(port): 27 | match port: 28 | 0: 29 | return "IN" 30 | 1: 31 | return "Amplitude" 32 | 2: 33 | return "Angular Frequency" 34 | 3: 35 | return "Phase" 36 | 4: 37 | return "Height" 38 | 39 | func _get_input_port_type(port): 40 | match port: 41 | 0: 42 | return VisualShaderNode.PORT_TYPE_SCALAR 43 | 1: 44 | return VisualShaderNode.PORT_TYPE_SCALAR 45 | 2: 46 | return VisualShaderNode.PORT_TYPE_SCALAR 47 | 3: 48 | return VisualShaderNode.PORT_TYPE_SCALAR 49 | 4: 50 | return VisualShaderNode.PORT_TYPE_SCALAR 51 | 52 | func _get_output_port_count(): 53 | return 1 54 | 55 | func _get_output_port_name(port): 56 | return "" 57 | 58 | func _get_output_port_type(port): 59 | return VisualShaderNode.PORT_TYPE_SCALAR 60 | 61 | func _get_global_code(mode): 62 | return """ 63 | float sine_wave_angular(float IN, float __amplitude, float __ang_frequency, float __phase, float __height) { 64 | return __amplitude * sin(__ang_frequency * IN + __phase) + __height; 65 | } 66 | """ 67 | 68 | func _get_code(input_vars, output_vars, mode, type): 69 | 70 | return "%s = sine_wave_angular(%s, %s, %s, %s, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2], input_vars[3], input_vars[4]] 71 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Wave/SquareWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeSquareWave 4 | 5 | func _init(): 6 | set_input_port_default_value(1, 2.0) 7 | set_input_port_default_value(2, 1.0) 8 | set_input_port_default_value(3, 0.0) 9 | 10 | func _get_name(): 11 | return "SquareWave" 12 | 13 | func _get_category(): 14 | return "VisualShaderExtras/Wave" 15 | 16 | func _get_description(): 17 | return "Square Wave function" 18 | 19 | func _get_return_icon_type(): 20 | return VisualShaderNode.PORT_TYPE_SCALAR 21 | 22 | func _get_input_port_count(): 23 | return 4 24 | 25 | func _get_input_port_name(port): 26 | match port: 27 | 0: 28 | return "IN" 29 | 1: 30 | return "Amplitude" 31 | 2: 32 | return "Frequency" 33 | 3: 34 | return "Height" 35 | 36 | func _get_input_port_type(port): 37 | match port: 38 | 0: 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 1: 41 | return VisualShaderNode.PORT_TYPE_SCALAR 42 | 2: 43 | return VisualShaderNode.PORT_TYPE_SCALAR 44 | 3: 45 | return VisualShaderNode.PORT_TYPE_SCALAR 46 | 47 | func _get_output_port_count(): 48 | return 1 49 | 50 | func _get_output_port_name(port): 51 | return "" 52 | 53 | func _get_output_port_type(port): 54 | return VisualShaderNode.PORT_TYPE_SCALAR 55 | 56 | func _get_global_code(mode): 57 | return """ 58 | float square_wave(float IN, float __amplitude, float __frequency, float __height) { 59 | return __amplitude*sign(sin(2.0 * PI * IN * __frequency)) + __height; 60 | } 61 | """ 62 | 63 | func _get_code(input_vars, output_vars, mode, type): 64 | 65 | return "%s = square_wave(%s, %s, %s, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2], input_vars[3]] 66 | -------------------------------------------------------------------------------- /addons/VisualShaderExtras/Wave/TriangleWave.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends VisualShaderNodeCustom 3 | class_name VisualShaderNodeTriangleWave 4 | 5 | func _init(): 6 | set_input_port_default_value(1, 2.0) 7 | set_input_port_default_value(2, 1.0) 8 | set_input_port_default_value(3, 0.0) 9 | 10 | func _get_name(): 11 | return "TriangleWave" 12 | 13 | func _get_category(): 14 | return "VisualShaderExtras/Wave" 15 | 16 | func _get_description(): 17 | return "Triangle Wave function" 18 | 19 | func _get_return_icon_type(): 20 | return VisualShaderNode.PORT_TYPE_SCALAR 21 | 22 | func _get_input_port_count(): 23 | return 4 24 | 25 | func _get_input_port_name(port): 26 | match port: 27 | 0: 28 | return "IN" 29 | 1: 30 | return "Amplitude" 31 | 2: 32 | return "Frequency" 33 | 3: 34 | return "Height" 35 | 36 | func _get_input_port_type(port): 37 | match port: 38 | 0: 39 | return VisualShaderNode.PORT_TYPE_SCALAR 40 | 1: 41 | return VisualShaderNode.PORT_TYPE_SCALAR 42 | 2: 43 | return VisualShaderNode.PORT_TYPE_SCALAR 44 | 3: 45 | return VisualShaderNode.PORT_TYPE_SCALAR 46 | 47 | func _get_output_port_count(): 48 | return 1 49 | 50 | func _get_output_port_name(port): 51 | return "" 52 | 53 | func _get_output_port_type(port): 54 | return VisualShaderNode.PORT_TYPE_SCALAR 55 | 56 | func _get_global_code(mode): 57 | return """ 58 | float triangle_wave(float IN, float __amplitude, float __frequency, float __height) { 59 | return 1.0 - __amplitude * abs(round(IN / __frequency) - (IN / __frequency)) + __height; 60 | } 61 | """ 62 | 63 | func _get_code(input_vars, output_vars, mode, type): 64 | 65 | return "%s = triangle_wave(%s, %s, %s, %s);" % [output_vars[0], input_vars[0], input_vars[1], input_vars[2], input_vars[3]] 66 | --------------------------------------------------------------------------------