From a17cba0041ef4f3b59e8ae8012f4923edcf1b55e Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Tue, 1 Feb 2022 16:23:24 +0100 Subject: [PATCH] Corrected update of deformation with dt Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- .../shaders/init_particle_volumes.comp | 4 ++++ projects/wobble_bobble/shaders/particle.inc | 2 +- .../shaders/update_particle_deformation.comp | 13 ++++++++++++- projects/wobble_bobble/src/main.cpp | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/projects/wobble_bobble/shaders/init_particle_volumes.comp b/projects/wobble_bobble/shaders/init_particle_volumes.comp index 9fde7700..8ab9f05b 100644 --- a/projects/wobble_bobble/shaders/init_particle_volumes.comp +++ b/projects/wobble_bobble/shaders/init_particle_volumes.comp @@ -43,10 +43,14 @@ void main() { } if (volume > 0.0f) { + float density = minimal.mass / volume; + //volume = minimal.mass / (mass / volume); + mass = density * volume; } particles[gl_GlobalInvocationID.x].minimal.size = sphere_radius(volume); + particles[gl_GlobalInvocationID.x].minimal.mass = mass; } memoryBarrierBuffer(); diff --git a/projects/wobble_bobble/shaders/particle.inc b/projects/wobble_bobble/shaders/particle.inc index 65580262..06608c2b 100644 --- a/projects/wobble_bobble/shaders/particle.inc +++ b/projects/wobble_bobble/shaders/particle.inc @@ -113,7 +113,7 @@ vec3 voxel_particle_grad_weight(vec3 voxel, ParticleMinimal particle) { grad_weight_C(delta.x), grad_weight_C(delta.y), grad_weight_C(delta.z) - ) * sign; + ) * sign / particle.size; return vec3( grad_weight.x * weight.y * weight.z, diff --git a/projects/wobble_bobble/shaders/update_particle_deformation.comp b/projects/wobble_bobble/shaders/update_particle_deformation.comp index 8cd2aabe..3cf9d2b9 100644 --- a/projects/wobble_bobble/shaders/update_particle_deformation.comp +++ b/projects/wobble_bobble/shaders/update_particle_deformation.comp @@ -12,6 +12,13 @@ layout(set=0, binding=0, std430) buffer particleBuffer { layout(set=0, binding=1) uniform texture3D gridImage; layout(set=0, binding=2) uniform sampler gridSampler; +layout( push_constant ) uniform constants { + float K; + float E; + float t; + float dt; +}; + void main() { memoryBarrierBuffer(); memoryBarrierImage(); @@ -45,7 +52,11 @@ void main() { } } - mat3 deformation_elastic = (mat3(1.0f) + velocity_gradient) * deformation; + mat3 deformation_elastic = deformation; + + if (dt > 0.0f) { + deformation_elastic = (mat3(1.0f) + dt * velocity_gradient) * deformation; + } particles[gl_GlobalInvocationID.x].deformation = mat4(deformation_elastic); } diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index 8b0a016b..02096dba 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -688,7 +688,7 @@ int main(int argc, const char **argv) { { vkcv::DescriptorSetUsage( 0, core.getDescriptorSet(updateParticleDeformationSets[0]).vulkanHandle ) }, - vkcv::PushConstants(0) + physicsPushConstants ); core.recordBufferMemoryBarrier(cmdStream, particles.getHandle()); -- GitLab