diff --git a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp index 691546585e4e418ebc8d9f63a87fdc555180d16e..990c5141c6de0875915992b70e90d7a7a2bf2b73 100644 --- a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp +++ b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp @@ -28,16 +28,21 @@ void main() { if (localOffset < particles.length()) { shared_particles[gl_LocalInvocationIndex] = particles[localOffset].minimal; - vec3 distance = (position - shared_particles[gl_LocalInvocationIndex].position); - - shared_particles[gl_LocalInvocationIndex].velocity += ( - mat3(particles[localOffset].mls) * distance + shared_particles[gl_LocalInvocationIndex].pad = ( + mat3(particles[localOffset].mls) * + (position - shared_particles[gl_LocalInvocationIndex].position) + ) + ( + shared_particles[gl_LocalInvocationIndex].velocity * + shared_particles[gl_LocalInvocationIndex].mass ); } else { shared_particles[gl_LocalInvocationIndex].position = vec3(0.0f); shared_particles[gl_LocalInvocationIndex].size = 0.0f; shared_particles[gl_LocalInvocationIndex].velocity = vec3(0.0f); shared_particles[gl_LocalInvocationIndex].mass = 0.0f; + + shared_particles[gl_LocalInvocationIndex].pad = vec3(0.0f); + shared_particles[gl_LocalInvocationIndex].weight_sum = 1.0f; } barrier(); @@ -45,11 +50,10 @@ void main() { for (uint i = 0; i < SHARED_PARTICLES_BATCH_SIZE; i++) { float weight = voxel_particle_weight(position, shared_particles[i]); - float mass = shared_particles[i].mass * weight; gridValue += vec4( - shared_particles[i].velocity * mass, - mass + shared_particles[i].pad * weight, + shared_particles[i].mass * weight ); } diff --git a/projects/wobble_bobble/shaders/update_particle_velocities.comp b/projects/wobble_bobble/shaders/update_particle_velocities.comp index e8d671e58e29b85b863f10363ffad581aa577870..f52224a77c1ea8781718baec2af03f13f0d5514f 100644 --- a/projects/wobble_bobble/shaders/update_particle_velocities.comp +++ b/projects/wobble_bobble/shaders/update_particle_velocities.comp @@ -81,15 +81,14 @@ void main() { if ((J > 0.0f) && (mass > 0.0f)) { mat3 F_T = transpose(F); - mat3 F_invT = inverse(F_T); - mat3 delta = lame2 * (F - F_invT) + lame1 * log(J) * F_invT; + mat3 delta = lame2 * (F * F_T - mat3(1.0f)) + lame1 * log(J); - //mls_Q += beta * dt * volume * particle.minimal.weight_sum * delta * F_T * D_inv / mass; + mls_Q += beta * dt * volume * delta * D_inv; } affine_C = affine_B * D_inv; - mls_Q += beta * affine_C; + mls_Q += beta * affine_C * mass; } F = (mat3(1.0f) + dt * affine_C) * F;