From f74c7a39720599ca7d4cdabd156e8d47ed850c17 Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Thu, 3 Feb 2022 14:56:23 +0100 Subject: [PATCH] Replaced check for zero with checks for NaN Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- projects/wobble_bobble/shaders/particle.inc | 63 +++---------------- .../shaders/transform_particles_to_grid.comp | 6 +- .../shaders/update_grid_forces.comp | 3 +- .../shaders/update_particle_velocities.comp | 4 +- 4 files changed, 14 insertions(+), 62 deletions(-) diff --git a/projects/wobble_bobble/shaders/particle.inc b/projects/wobble_bobble/shaders/particle.inc index 77d2691e..68704b36 100644 --- a/projects/wobble_bobble/shaders/particle.inc +++ b/projects/wobble_bobble/shaders/particle.inc @@ -56,76 +56,27 @@ float weight_C(float x) { } float voxel_particle_weight(vec3 voxel, ParticleMinimal particle) { - if (particle.size <= 0.0f) { + vec3 delta = abs(particle.position - voxel) / particle.size; + + if (any(isnan(delta)) || any(isinf(delta))) { return 0.0f; } - vec3 delta = abs(particle.position - voxel) / particle.size; - vec3 weight = vec3( weight_C(delta.x), weight_C(delta.y), weight_C(delta.z) ); - return ( + float result = ( weight.x * weight.y * weight.z ) / particle.weight_sum; -} - -float grad_weight_A(float x) { - return -1.0f; -} - -float grad_weight_B(float x) { - if (x < 0.5f) { - return -2.0f * x; - } else - if (x < 1.5f) { - return -1.5f + x; - } else { + + if ((isnan(result)) || (isinf(result))) { return 0.0f; - } -} - -float grad_weight_C(float x) { - if (x < 1.0f) { - return 1.5f * x * x - 2.0f * x; - } else - if (x < 2.0f) { - float y = (2.0f - x); - return -0.5f * y * y; } else { - return 0.0f; + return result; } } -vec3 voxel_particle_grad_weight(vec3 voxel, ParticleMinimal particle) { - if (particle.size <= 0.0f) { - return vec3(0.0f); - } - - vec3 sign_delta = (particle.position - voxel) / particle.size; - vec3 delta = abs(sign_delta); - vec3 sign = sign(sign_delta); - - vec3 weight = vec3( - weight_C(delta.x), - weight_C(delta.y), - weight_C(delta.z) - ); - - vec3 grad_weight = vec3( - grad_weight_C(delta.x), - grad_weight_C(delta.y), - grad_weight_C(delta.z) - ) * sign / particle.size; - - return vec3( - grad_weight.x * weight.y * weight.z, - grad_weight.y * weight.z * weight.x, - grad_weight.z * weight.x * weight.y - ) / particle.weight_sum; -} - #endif // PARTICLE_INC \ No newline at end of file diff --git a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp index 990c5141..f2c2401c 100644 --- a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp +++ b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp @@ -61,8 +61,10 @@ void main() { memoryBarrierShared(); } - if (gridValue.w > 0.0f) { - gridValue.xyz /= gridValue.w; + gridValue.xyz /= gridValue.w; + + if (any(isnan(gridValue.xyz)) || any(isinf(gridValue.xyz))) { + gridValue.xyz = vec3(0.0f); } barrier(); diff --git a/projects/wobble_bobble/shaders/update_grid_forces.comp b/projects/wobble_bobble/shaders/update_grid_forces.comp index 9c0d0c07..73292a25 100644 --- a/projects/wobble_bobble/shaders/update_grid_forces.comp +++ b/projects/wobble_bobble/shaders/update_grid_forces.comp @@ -33,7 +33,6 @@ void main() { const vec3 gridResolution = vec3(imageSize(gridImage)); const vec3 position = (vec3(gl_GlobalInvocationID) + vec3(0.5f)) / gridResolution; - const float h3 = 1.0f / gridResolution.x / gridResolution.y / gridResolution.z; vec4 gridSample = imageLoad( gridImage, @@ -47,7 +46,7 @@ void main() { memoryBarrierBuffer(); if (mass > 0.0f) { - velocity += vec3(0.0f, -9.81f * dt * 0.0f, 0.0f); + velocity += vec3(0.0f, -9.81f * dt, 0.0f); } bvec3 lowerID = lessThanEqual(gl_GlobalInvocationID, ivec3(0)); diff --git a/projects/wobble_bobble/shaders/update_particle_velocities.comp b/projects/wobble_bobble/shaders/update_particle_velocities.comp index f52224a7..5a55400b 100644 --- a/projects/wobble_bobble/shaders/update_particle_velocities.comp +++ b/projects/wobble_bobble/shaders/update_particle_velocities.comp @@ -79,12 +79,12 @@ void main() { mat3 D_inv = inverse(affine_D); float J = determinant(F); - if ((J > 0.0f) && (mass > 0.0f)) { + if (J > 0.0f) { mat3 F_T = transpose(F); mat3 delta = lame2 * (F * F_T - mat3(1.0f)) + lame1 * log(J); - mls_Q += beta * dt * volume * delta * D_inv; + mls_Q -= beta * dt * volume * delta * D_inv; } affine_C = affine_B * D_inv; -- GitLab