diff --git a/projects/wobble_bobble/shaders/particle.inc b/projects/wobble_bobble/shaders/particle.inc index 77d2691ee4c0774e75a09f1ebeba3ba906e4d519..68704b366d56717595858509a80c698d1db5d550 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 990c5141c6de0875915992b70e90d7a7a2bf2b73..f2c2401c214bcee9f42c97665485cb24151493fc 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 9c0d0c073939c9d1f2d8ecee595655c2f604906e..73292a25cd9a32c103a57a15a3542ad827d20832 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 f52224a77c1ea8781718baec2af03f13f0d5514f..5a55400b05fc7d2784944bdf0dbe1b24b9008a28 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;