commit 0770c3b8fcac2c44cb53e210493d4c776591bb76 Author: Josef Date: Sun May 5 10:56:09 2024 +0200 Initial Commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0035ad6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Godot 4+ specific ignores +.godot/ + +# Godot-specific ignores +.import/ +export.cfg +export_presets.cfg + +# Imported translations (automatically generated from CSV files) +*.translation + +# Mono-specific ignores +.mono/ +data_*/ +mono_crash.*.json \ No newline at end of file diff --git a/Main.tscn b/Main.tscn new file mode 100644 index 0000000..ab7c300 --- /dev/null +++ b/Main.tscn @@ -0,0 +1,66 @@ +[gd_scene load_steps=4 format=3 uid="uid://vaciccy1o11a"] + +[ext_resource type="PackedScene" uid="uid://dtgriufr13bf6" path="res://Sphere/sphere-64-32.glb" id="1_61cjg"] +[ext_resource type="Material" uid="uid://b2o4bv3mf55bs" path="res://MetaBallsMaterial.tres" id="2_8psci"] +[ext_resource type="Script" path="res://MetaBallAssigner.cs" id="3_6ub3h"] + +[node name="Node3D" type="Node3D"] + +[node name="A" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(0.997, 0, 0, 0, 0.997, 0, 0, 0, 0.997, -0.308231, 10.7077, 0.0319376) +metadata/_edit_group_ = true + +[node name="Sphere" parent="A" index="0"] +material_override = ExtResource("2_8psci") + +[node name="B" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.12513, 13.8768, 0) +metadata/_edit_group_ = true + +[node name="Sphere" parent="B" index="0"] +material_override = ExtResource("2_8psci") + +[node name="C" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.32795, 6.55321, 0) +metadata/_edit_group_ = true + +[node name="Sphere" parent="C" index="0"] +material_override = ExtResource("2_8psci") + +[node name="D" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.23827, 8.75391, 0) +metadata/_edit_group_ = true + +[node name="Sphere" parent="D" index="0"] +material_override = ExtResource("2_8psci") + +[node name="E" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.68133, 11.5801, 0) +metadata/_edit_group_ = true + +[node name="Sphere" parent="E" index="0"] +material_override = ExtResource("2_8psci") + +[node name="F" parent="." instance=ExtResource("1_61cjg")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.75614, 12.9259, 0) +metadata/_edit_group_ = true + +[node name="Sphere" parent="F" index="0"] +material_override = ExtResource("2_8psci") + +[node name="MetaBallAssigner" type="Node" parent="." node_paths=PackedStringArray("metaBallA", "metaBallB", "metaBallC", "metaBallD", "metaBallE", "metaBallF")] +script = ExtResource("3_6ub3h") +metaBallA = NodePath("../A") +metaBallB = NodePath("../B") +metaBallC = NodePath("../C") +metaBallD = NodePath("../D") +metaBallE = NodePath("../E") +metaBallF = NodePath("../F") +material = ExtResource("2_8psci") + +[editable path="A"] +[editable path="B"] +[editable path="C"] +[editable path="D"] +[editable path="E"] +[editable path="F"] diff --git a/Meta.tres b/Meta.tres new file mode 100644 index 0000000..13c5f21 --- /dev/null +++ b/Meta.tres @@ -0,0 +1,8 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://dwu5fd56pjr8q"] + +[ext_resource type="Shader" uid="uid://dr2k3gqeaitso" path="res://MetaVS.tres" id="1_lu1pw"] + +[resource] +render_priority = 0 +shader = ExtResource("1_lu1pw") +shader_parameter/MetaBallA = null diff --git a/MetaBallAssigner.cs b/MetaBallAssigner.cs new file mode 100644 index 0000000..411a9b1 --- /dev/null +++ b/MetaBallAssigner.cs @@ -0,0 +1,49 @@ +using Godot; +using System; +using System.Collections.Generic; + +[Tool] +public partial class MetaBallAssigner : Node +{ + [Export] + public Node3D metaBallA; + + [Export] + public Node3D metaBallB; + + [Export] + public Node3D metaBallC; + + [Export] + public Node3D metaBallD; + + [Export] + public Node3D metaBallE; + + [Export] + public Node3D metaBallF; + + [Export] + public ShaderMaterial material; + + + public override void _Process( double delta ) + { + GD.Print( "AS" ); + SetMetaBall( metaBallA, "A" ); + SetMetaBall( metaBallB, "B" ); + SetMetaBall( metaBallC, "C" ); + + SetMetaBall( metaBallD, "D" ); + SetMetaBall( metaBallE, "E" ); + SetMetaBall( metaBallF, "F" ); + } + + void SetMetaBall( Node3D node, string metaBallIndex ) + { + var location = node.GlobalPosition; + var scale = node.Scale.Length(); + var value = new Vector4( location.X, location.Y, location.Z, scale ); + material.SetShaderParameter( "metaBall" + metaBallIndex, value ); + } +} diff --git a/MetaBalls.csproj b/MetaBalls.csproj new file mode 100644 index 0000000..d7de074 --- /dev/null +++ b/MetaBalls.csproj @@ -0,0 +1,8 @@ + + + net6.0 + net7.0 + net8.0 + true + + \ No newline at end of file diff --git a/MetaBalls.gdshader b/MetaBalls.gdshader new file mode 100644 index 0000000..592588a --- /dev/null +++ b/MetaBalls.gdshader @@ -0,0 +1,76 @@ +shader_type spatial; + +uniform vec4 metaBallA; +uniform vec4 metaBallB; +uniform vec4 metaBallC; +uniform vec4 metaBallD; +uniform vec4 metaBallE; +uniform vec4 metaBallF; +uniform float maxReach = 2; +uniform float metaSize = 1; +uniform float maxInfluence = 0.1; +uniform float dotInfluence:hint_range(0.0,1.0) = 0.1; +uniform sampler2D dotInfluenceCurve; +uniform float pointVSdirectionalAttraction:hint_range(0.0,1.0) = 0.5; +uniform sampler2D curve; + + +vec3 getInfluence( vec3 position, vec3 normal, vec4 metaBall, vec3 ownCenter ) +{ + vec3 metaPosition = metaBall.xyz; + vec3 centerTowardsMeta = metaPosition - ownCenter; + + vec3 direction = length( centerTowardsMeta ) == 0.0 ? vec3( 0, 0, 0 ) : normalize( centerTowardsMeta ); + + vec3 towardsMeta = position - metaPosition; + float distance = length( towardsMeta ); + vec3 directectedMetaPosition = position + direction * distance; + + vec3 influencePosition = mix( metaPosition, directectedMetaPosition, pointVSdirectionalAttraction ); + + float dotProduct = max( 0, dot( normal, normalize( -towardsMeta ) ) ); + + dotProduct = texture( dotInfluenceCurve, vec2( dotProduct, 0.0 ) ).r; + + float sd = distance - metaSize; + + sd = sd/maxReach; + + sd = clamp( sd, 0.0, 1.0 ); + + float amount = 1.0 - texture( curve, vec2( sd, 0.0 ) ).r; + + vec3 influence = mix( influencePosition, position, amount ) - position; + //influence = vec3( 0, 0, 0 ); + return influence * ( mix( 1.0, dotProduct, dotInfluence ) ); +} + +void vertex() +{ + vec3 influence = vec3( 0, 0, 0 ); + vec3 worldPosition = ( MODEL_MATRIX * vec4( VERTEX, 1.0 ) ).xyz; + vec3 worldNormal = NORMAL; + vec3 ownCenter = ( MODEL_MATRIX * vec4( 0.00000, 0.00000, 0.00000, 1.0 ) ).xyz; + + + influence += getInfluence( worldPosition, worldNormal, metaBallA, ownCenter ); + influence += getInfluence( worldPosition, worldNormal, metaBallB, ownCenter ); + influence += getInfluence( worldPosition, worldNormal, metaBallC, ownCenter ); + influence += getInfluence( worldPosition, worldNormal, metaBallD, ownCenter ); + influence += getInfluence( worldPosition, worldNormal, metaBallE, ownCenter ); + influence += getInfluence( worldPosition, worldNormal, metaBallF, ownCenter ); + + worldPosition += influence * maxInfluence; + + VERTEX = ( inverse( MODEL_MATRIX ) * vec4( worldPosition, 1.0 ) ).xyz; +} + +void fragment() +{ + +} + +void light() +{ + +} diff --git a/MetaBalls.sln b/MetaBalls.sln new file mode 100644 index 0000000..d2ff416 --- /dev/null +++ b/MetaBalls.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetaBalls", "MetaBalls.csproj", "{A6CD2366-820B-4C26-A18F-B0D5C7BA497E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {A6CD2366-820B-4C26-A18F-B0D5C7BA497E}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/MetaBallsMaterial.tres b/MetaBallsMaterial.tres new file mode 100644 index 0000000..ef50ffe --- /dev/null +++ b/MetaBallsMaterial.tres @@ -0,0 +1,34 @@ +[gd_resource type="ShaderMaterial" load_steps=6 format=3 uid="uid://b2o4bv3mf55bs"] + +[ext_resource type="Shader" path="res://MetaBalls.gdshader" id="1_bba4x"] + +[sub_resource type="Curve" id="Curve_ecl03"] +_data = [Vector2(0.0289017, 0), 0.0, 0.0, 0, 0, Vector2(0.184971, 1), 0.0, 0.0, 0, 0, Vector2(0.965318, 0), -2.78227, 0.0, 0, 0] +point_count = 3 + +[sub_resource type="CurveTexture" id="CurveTexture_gec5v"] +curve = SubResource("Curve_ecl03") + +[sub_resource type="Curve" id="Curve_3868r"] +_data = [Vector2(0, 0), 0.0, 0.908578, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_35ykf"] +curve = SubResource("Curve_3868r") + +[resource] +render_priority = 0 +shader = ExtResource("1_bba4x") +shader_parameter/metaBallA = Vector4(-0.308231, 10.7077, 0.0319376, 1.72685) +shader_parameter/metaBallB = Vector4(-6.12513, 13.8768, 0, 1.73205) +shader_parameter/metaBallC = Vector4(-3.32795, 6.55321, 0, 1.73205) +shader_parameter/metaBallD = Vector4(-1.23827, 8.75391, 0, 1.73205) +shader_parameter/metaBallE = Vector4(-5.68133, 11.5801, 0, 1.73205) +shader_parameter/metaBallF = Vector4(-3.75614, 12.9259, 0, 1.73205) +shader_parameter/maxReach = 2.0 +shader_parameter/metaSize = 0.0 +shader_parameter/maxInfluence = 1.0 +shader_parameter/dotInfluence = 1.0 +shader_parameter/pointVSdirectionalAttraction = 1.0 +shader_parameter/dotInfluenceCurve = SubResource("CurveTexture_35ykf") +shader_parameter/curve = SubResource("CurveTexture_gec5v") diff --git a/MetaVS.tres b/MetaVS.tres new file mode 100644 index 0000000..d461cb0 --- /dev/null +++ b/MetaVS.tres @@ -0,0 +1,33 @@ +[gd_resource type="VisualShader" load_steps=3 format=3 uid="uid://dr2k3gqeaitso"] + +[sub_resource type="VisualShaderNodeVec4Parameter" id="VisualShaderNodeVec4Parameter_haltq"] +output_port_for_preview = 0 +parameter_name = "MetaBallA" + +[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_q7wmx"] +input_name = "modelview_matrix" + +[resource] +code = "shader_type spatial; +render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx; + +uniform vec4 MetaBallA; + + + +void vertex() { +// Vector4Parameter:2 + vec4 n_out2p0 = MetaBallA; + + +// Output:0 + NORMAL = vec3(n_out2p0.xyz); + + +} +" +nodes/vertex/2/node = SubResource("VisualShaderNodeVec4Parameter_haltq") +nodes/vertex/2/position = Vector2(-120, 40) +nodes/vertex/3/node = SubResource("VisualShaderNodeInput_q7wmx") +nodes/vertex/3/position = Vector2(-400, 160) +nodes/vertex/connections = PackedInt32Array(2, 0, 0, 1) diff --git a/Sphere/sphere-64-32.blend b/Sphere/sphere-64-32.blend new file mode 100644 index 0000000..1653c14 Binary files /dev/null and b/Sphere/sphere-64-32.blend differ diff --git a/Sphere/sphere-64-32.blend.import b/Sphere/sphere-64-32.blend.import new file mode 100644 index 0000000..9dc3ac5 --- /dev/null +++ b/Sphere/sphere-64-32.blend.import @@ -0,0 +1,50 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://c22xg8xkp5rj" +path="res://.godot/imported/sphere-64-32.blend-ac22282527d30f434a903a47af459dc3.scn" + +[deps] + +source_file="res://Sphere/sphere-64-32.blend" +dest_files=["res://.godot/imported/sphere-64-32.blend-ac22282527d30f434a903a47af459dc3.scn"] + +[params] + +nodes/root_type="" +nodes/root_name="" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +meshes/force_disable_compression=false +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +animation/remove_immutable_tracks=true +import_script/path="" +_subresources={} +gltf/naming_version=1 +gltf/embedded_image_handling=1 +blender/nodes/visible=0 +blender/nodes/punctual_lights=true +blender/nodes/cameras=true +blender/nodes/custom_properties=true +blender/nodes/modifiers=1 +blender/meshes/colors=false +blender/meshes/uvs=true +blender/meshes/normals=true +blender/meshes/tangents=true +blender/meshes/skins=2 +blender/meshes/export_bones_deforming_mesh_only=false +blender/materials/unpack_enabled=true +blender/materials/export_materials=1 +blender/animation/limit_playback=true +blender/animation/always_sample=true +blender/animation/group_tracks=true diff --git a/Sphere/sphere-64-32.glb b/Sphere/sphere-64-32.glb new file mode 100644 index 0000000..5d15073 Binary files /dev/null and b/Sphere/sphere-64-32.glb differ diff --git a/Sphere/sphere-64-32.glb.import b/Sphere/sphere-64-32.glb.import new file mode 100644 index 0000000..4b8c1da --- /dev/null +++ b/Sphere/sphere-64-32.glb.import @@ -0,0 +1,34 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://dtgriufr13bf6" +path="res://.godot/imported/sphere-64-32.glb-8e002b6e7a495f524cf114c4cd4939d1.scn" + +[deps] + +source_file="res://Sphere/sphere-64-32.glb" +dest_files=["res://.godot/imported/sphere-64-32.glb-8e002b6e7a495f524cf114c4cd4939d1.scn"] + +[params] + +nodes/root_type="" +nodes/root_name="" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +meshes/force_disable_compression=false +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +animation/remove_immutable_tracks=true +import_script/path="" +_subresources={} +gltf/naming_version=1 +gltf/embedded_image_handling=1 diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..a6b8974 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://db7fv3k363cwx" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/material-base.tres b/material-base.tres new file mode 100644 index 0000000..146cd5e --- /dev/null +++ b/material-base.tres @@ -0,0 +1,5 @@ +[gd_resource type="StandardMaterial3D" format=3 uid="uid://dtov85hqtpj5b"] + +[resource] +grow = true +grow_amount = 16.0 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..22ee45c --- /dev/null +++ b/project.godot @@ -0,0 +1,20 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="MetaBalls" +run/main_scene="res://Main.tscn" +config/features=PackedStringArray("4.2", "C#", "Forward Plus") +config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="MetaBalls"