From 339480741d17f7e79e8eedcfc321102835fcc397 Mon Sep 17 00:00:00 2001 From: Vanessa Karolek <vaka1997@uni-koblenz.de> Date: Thu, 3 Feb 2022 01:39:24 +0100 Subject: [PATCH] add material type selection for choosing material presets actual implemented material types are: - glass - wood - ice - rubber (interestingly results in negative compression values o.o) - undefined (is automatically set, if preset values are changed) main.cpp uses glass as first chosen material. you can choose another material presets via the dropdown menu. this will adjust the values for elasticity and compression. elasticity and compression are given in GPa, thus values will be multiplied with 1E9 when the material is being recalculated. update_grid_forces does no longer calculate all physics values from E and K. the lame constants are calculated in the material itself. so, the physics structure does only contain time parameters and the lame constants, else the other values would be redundant. --- projects/wobble_bobble/CMakeLists.txt | 3 +- .../shaders/update_grid_forces.comp | 20 +---- projects/wobble_bobble/src/Material.hpp | 76 +++++++++++++++++++ projects/wobble_bobble/src/main.cpp | 63 ++++++++------- 4 files changed, 115 insertions(+), 47 deletions(-) create mode 100644 projects/wobble_bobble/src/Material.hpp diff --git a/projects/wobble_bobble/CMakeLists.txt b/projects/wobble_bobble/CMakeLists.txt index 9842b13b..c5dc9cba 100644 --- a/projects/wobble_bobble/CMakeLists.txt +++ b/projects/wobble_bobble/CMakeLists.txt @@ -10,7 +10,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) # adding source files to the project add_executable(wobble_bobble - src/main.cpp) + src/main.cpp + src/Material.hpp) fix_project(wobble_bobble) diff --git a/projects/wobble_bobble/shaders/update_grid_forces.comp b/projects/wobble_bobble/shaders/update_grid_forces.comp index 0cc83a26..7db54625 100644 --- a/projects/wobble_bobble/shaders/update_grid_forces.comp +++ b/projects/wobble_bobble/shaders/update_grid_forces.comp @@ -12,8 +12,8 @@ layout(set=0, binding=2, std430) readonly buffer particleBuffer { }; layout( push_constant ) uniform constants { - float K; - float E; + float lame1; + float lame2; float t; float dt; }; @@ -23,22 +23,6 @@ layout( push_constant ) uniform constants { shared Particle shared_particles [SHARED_PARTICLES_BATCH_SIZE]; void main() { - const float K9_E = (9.0f * K - E); - - float lame1 = 3.0f * K * (3.0f * K - E); - float lame2 = 3.0f * K * E; - float poisson = (3.0f * K - E); - float M = 3.0f * K * (3.0f * K + E); - - if (K9_E > 0.0f) { - lame1 /= K9_E; - lame2 /= K9_E; - M /= K9_E; - } - - if (K > 0.0f) { - poisson /= (6.0f * K); - } barrier(); memoryBarrierBuffer(); diff --git a/projects/wobble_bobble/src/Material.hpp b/projects/wobble_bobble/src/Material.hpp new file mode 100644 index 00000000..3da7a413 --- /dev/null +++ b/projects/wobble_bobble/src/Material.hpp @@ -0,0 +1,76 @@ +#pragma once + +enum MaterialType { + UNDEFINED = 0, GLASS = 1, WOOD = 2, ICE = 3, RUBBER = 4 +}; + +struct Material { + MaterialType m_type; + + float m_compression = 0.0f; // K - compression modulus, given in GPa (multiple of 10^9) + float m_elasticity = 0.0f; // E - elasticity modulus, given in GPa (multiple of 10^9) + float m_shear = 0.0f; // G - shear modulus, given in GPa (multiple of 10^9) + float m_lame1 = 0.0f; // lambda + float m_lame2 = 0.0f; // mu + float m_poission = 0.0f; // nu + float m_longitudinal = 0.0f; // M + + Material(MaterialType materialType = GLASS) { + float K9_E; + switch (materialType) { + case UNDEFINED: + break; + case GLASS: + m_shear = 26.2f * 1E9; // valid for room temperature, data extracted from here: https://de.wikipedia.org/wiki/Schubmodul + m_elasticity = 65.0f * 1E9; // 40 ... 90, data extracted from here: https://de.wikipedia.org/wiki/Elastizitätsmodul + m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity); // 35 ... 55 + m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression); + K9_E = (9.0f * m_compression - m_elasticity); + m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E; + m_lame2 = 3.0f * m_compression * m_elasticity / K9_E; + m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E; + break; + case WOOD: + m_shear = 4.0f * 1E9; // data extracted from here: https://en.wikipedia.org/wiki/Shear_modulus + m_elasticity = 11.0f * 1E9; // data extracted from here: https://de.wikipedia.org/wiki/Holz#Eigenschaften + m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity); + m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression); + K9_E = (9.0f * m_compression - m_elasticity); + m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E; + m_lame2 = 3.0f * m_compression * m_elasticity / K9_E; + m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E; + break; + case ICE: + m_elasticity = 10.0f * 1E9; // data extracted from here: https://www.yumpu.com/de/document/read/21025809/elastizitatsmodul-e-schubmodul-g-kompressionsmodul-k- + m_shear = 3.6f * 1E9; // data extracted from here: https://www.yumpu.com/de/document/read/21025809/elastizitatsmodul-e-schubmodul-g-kompressionsmodul-k- + m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity); + m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression); + K9_E = (9.0f * m_compression - m_elasticity); + m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E; + m_lame2 = 3.0f * m_compression * m_elasticity / K9_E; + m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E; + break; + case RUBBER: + m_elasticity = 0.05f * 1E9; // data extracted from here: https://www.tf.uni-kiel.de/matwis/amat/mw1_ge/kap_7/illustr/t7_1_2.html + m_shear = 0.0003f * 1E9; // data extracted from here: https://www.chemie-schule.de/KnowHow/Schubmodul + m_compression = m_shear * m_elasticity / (9.0f * m_shear - 3.0f * m_elasticity); + m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression); + K9_E = (9.0f * m_compression - m_elasticity); + m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E; + m_lame2 = 3.0f * m_compression * m_elasticity / K9_E; + m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E; + } + } + + void recalculate(float elasticityModulus, float compressionModulus) { + m_type = UNDEFINED; + m_elasticity = elasticityModulus * 1E9; + m_compression = compressionModulus * 1E9; + float K9_E = (9.0f * m_compression - m_elasticity); + m_shear = 3.0f * m_compression * m_elasticity / K9_E; + m_poission = (3.0f * m_compression - m_elasticity) / (6.0f * m_compression); + m_lame1 = (3.0f * m_compression * (3.0f * m_compression - m_elasticity)) / K9_E; + m_lame2 = 3.0f * m_compression * m_elasticity / K9_E; + m_longitudinal = 3.0f * m_compression * (3.0f * m_compression + m_elasticity) / K9_E; + } +}; \ No newline at end of file diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index 5294f1ae..079f3562 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -3,6 +3,7 @@ #include <vkcv/camera/CameraManager.hpp> #include <vkcv/gui/GUI.hpp> #include <vkcv/shader/GLSLCompiler.hpp> +#include "Material.hpp" #include <random> @@ -15,8 +16,8 @@ struct Particle { }; struct Physics { - float K; - float E; + float lame1; + float lame2; float t; float dt; }; @@ -164,7 +165,9 @@ int main(int argc, const char **argv) { swapchainExtent.width, swapchainExtent.height ).getHandle(); - + + int selectedMaterial = 1; + Material material(static_cast<MaterialType>(selectedMaterial)); glm::vec3 initialVelocity (0.0f, 1.0f, 0.0f); float density = 2500.0f; float radius = 0.1f; @@ -550,13 +553,9 @@ int main(int argc, const char **argv) { bool initializedParticleVolumes = false; bool renderGrid = true; - // Glass is glass and glass breaks... - float compression_modulus = 65.0f; - int compression_exponent = 9; - - float elasticity_modulus = 45.0f; - int elasticity_exponent = 9; - + float compression_modulus = material.m_compression / 1E9; + float elasticity_modulus = material.m_elasticity / 1E9; + float alpha = 1.0f; float beta = 0.0f; @@ -593,8 +592,8 @@ int main(int argc, const char **argv) { current = next; Physics physics; - physics.K = static_cast<float>(compression_modulus * std::pow(10.0, compression_exponent)); - physics.E = static_cast<float>(elasticity_modulus * std::pow(10.0, elasticity_exponent)); + physics.lame1 = material.m_lame1; + physics.lame2 = material.m_lame2; physics.t = static_cast<float>(0.000001 * static_cast<double>(time.count())); physics.dt = static_cast<float>(0.000001 * static_cast<double>(deltatime.count())); @@ -782,7 +781,21 @@ int main(int argc, const char **argv) { gui.beginGUI(); ImGui::Begin("Settings"); - + + ImGui::BeginGroup(); + const char* types[] = {"undefined", "glass", "wood", "ice", "rubber"}; + if (ImGui::Combo("MaterialType", &selectedMaterial, types, IM_ARRAYSIZE(types))) { + if (static_cast<MaterialType>(selectedMaterial) == MaterialType::UNDEFINED) { + material.m_type = MaterialType::UNDEFINED; + } + else { + material = Material(static_cast<MaterialType>(selectedMaterial)); + compression_modulus = material.m_compression / 1E9; + elasticity_modulus = material.m_elasticity / 1E9; + } + } + ImGui::EndGroup(); + ImGui::SliderFloat("Density", &density, std::numeric_limits<float>::epsilon(), 5000.0f); ImGui::SameLine(0.0f, 10.0f); if (ImGui::SmallButton("Reset##density")) { @@ -794,24 +807,18 @@ int main(int argc, const char **argv) { if (ImGui::SmallButton("Reset##radius")) { radius = 0.1f; } - + ImGui::BeginGroup(); - ImGui::SliderFloat("Compression Modulus", &compression_modulus, 0.0f, 500.0f); - ImGui::SliderInt("##compression_exponent", &compression_exponent, 1, 9); - ImGui::SameLine(0.0f, 10.0f); - if (ImGui::SmallButton("Reset##compression")) { - compression_modulus = 65.0f; - compression_exponent = 9; + if (ImGui::SliderFloat("Compression Modulus", &compression_modulus, 0.0f, 500.0f)) { + selectedMaterial = 0; + material.recalculate(elasticity_modulus, compression_modulus); } ImGui::EndGroup(); ImGui::BeginGroup(); - ImGui::SliderFloat("Elasticity Modulus", &elasticity_modulus, 0.0f, 1000.0f); - ImGui::SliderInt("##elasticity_exponent", &elasticity_exponent, 1, 9); - ImGui::SameLine(0.0f, 10.0f); - if (ImGui::SmallButton("Reset##elasticity")) { - elasticity_modulus = 45.0f; - elasticity_exponent = 9; + if (ImGui::SliderFloat("Elasticity Modulus", &elasticity_modulus, 0.0f, 1000.0f)) { + selectedMaterial = 0; + material.recalculate(elasticity_modulus, compression_modulus); } ImGui::EndGroup(); @@ -821,13 +828,13 @@ int main(int argc, const char **argv) { ImGui::SliderFloat("Alpha (PIC -> FLIP)", &alpha, 0.0f, 1.0f); ImGui::SameLine(0.0f, 10.0f); if (ImGui::SmallButton("Reset##alpha")) { - alpha = 0.5f; + alpha =1.0f; } ImGui::SliderFloat("Beta (Alpha -> APIC)", &beta, 0.0f, 1.0f); ImGui::SameLine(0.0f, 10.0f); if (ImGui::SmallButton("Reset##beta")) { - beta = 0.75f; + beta = 0.0f; } ImGui::DragFloat3("Initial Velocity", reinterpret_cast<float*>(&initialVelocity), 0.001f); -- GitLab