diff --git a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp index 6a15c5fd1ebe5dc4c35e36f9379c8b0723b4ff3d..ab5c30b297eddcdf4d5fd086c2e85fe0ce710ad4 100644 --- a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp +++ b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp @@ -20,6 +20,7 @@ void main() { const vec3 position = (vec3(gl_GlobalInvocationID) + vec3(0.5f)) / imageSize(gridImage); vec4 gridValue = vec4(0.0f); + uint offset = 0; memoryBarrierBuffer(); @@ -40,13 +41,20 @@ void main() { memoryBarrierShared(); for (uint i = 0; i < SHARED_PARTICLES_BATCH_SIZE; i++) { - gridValue += ( - vec4(shared_particles[i].velocity, shared_particles[i].mass) * - voxel_particle_weight(position, shared_particles[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 ); } } + if (gridValue.w > 0.0f) { + gridValue.xyz /= gridValue.w; + } + imageStore( gridImage, ivec3(gl_GlobalInvocationID), diff --git a/projects/wobble_bobble/shaders/update_particle_deformation.comp b/projects/wobble_bobble/shaders/update_particle_deformation.comp index 8cd2aabe439764d4572502667d3f587d2f8726e5..d6b585d771380e800727d57d3fed90f0fc19656e 100644 --- a/projects/wobble_bobble/shaders/update_particle_deformation.comp +++ b/projects/wobble_bobble/shaders/update_particle_deformation.comp @@ -36,10 +36,11 @@ void main() { if (length(offset) < minimal.size * 2.0f) { vec4 gridSample = texture(sampler3D(gridImage, gridSampler), voxel); - velocity_gradient += outerProduct( + // TODO: needs to be activated once everything else is stable! + /*velocity_gradient += outerProduct( gridSample.xyz, voxel_particle_grad_weight(voxel, minimal) - ); + );*/ } } } diff --git a/projects/wobble_bobble/shaders/update_particle_velocities.comp b/projects/wobble_bobble/shaders/update_particle_velocities.comp index 63f519a38d3cd1e783bbac2c19f4bf8e96301f3c..53b2af964a9b53b97cf5a8fbda52a9efc3b02bf9 100644 --- a/projects/wobble_bobble/shaders/update_particle_velocities.comp +++ b/projects/wobble_bobble/shaders/update_particle_velocities.comp @@ -14,6 +14,10 @@ layout(set=0, binding=1) uniform texture3D gridImage; layout(set=0, binding=2) uniform texture3D gridOldImage; layout(set=0, binding=3) uniform sampler gridSampler; +layout( push_constant ) uniform constants { + float alpha; +}; + void main() { memoryBarrierBuffer(); memoryBarrierImage(); @@ -48,7 +52,7 @@ void main() { } } - particles[gl_GlobalInvocationID.x].minimal.velocity = mix(velocity_pic, velocity_flip, 0.95f); + particles[gl_GlobalInvocationID.x].minimal.velocity = mix(velocity_pic, velocity_flip, alpha); } memoryBarrierBuffer(); diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index ee5dd9cd9e7c1a0d2e98d5ccd93d022e6633071e..ae846a9086cabd48f87f8895bacd5875f0ed08c0 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -21,7 +21,8 @@ float randomFloat(float min, float max) { return min + (max - min) * dist(random_dev) / static_cast<float>(RAND_MAX); } -void distributeParticles(Particle *particles, size_t count, const glm::vec3& center, float radius, float mass) { +void distributeParticles(Particle *particles, size_t count, const glm::vec3& center, float radius, + float mass, const glm::vec3& velocity) { float volume = 0.0f; for (size_t i = 0; i < count; i++) { @@ -40,7 +41,7 @@ void distributeParticles(Particle *particles, size_t count, const glm::vec3& cen particles[i].position = center + offset; particles[i].size = size; - particles[i].velocity = glm::vec3(0.0f); + particles[i].velocity = velocity; volume += size; } @@ -137,7 +138,8 @@ int main(int argc, const char **argv) { particles_vec.size(), glm::vec3(0.5f), 0.05f, - 0.27f + 0.27f, + glm::vec3(0.0f, 0.1f, 0.0f) ); particles.fill(particles_vec); @@ -519,6 +521,7 @@ int main(int argc, const char **argv) { bool initializedParticleVolumes = false; bool renderGrid = true; + float alpha = 0.95f; auto start = std::chrono::system_clock::now(); auto current = start; @@ -559,6 +562,9 @@ int main(int argc, const char **argv) { timePushConstants.appendDrawcall(static_cast<float>(t)); timePushConstants.appendDrawcall(static_cast<float>(dt)); + vkcv::PushConstants tweakPushConstants (sizeof(float)); + tweakPushConstants.appendDrawcall(static_cast<float>(alpha)); + cameraManager.update(dt); glm::mat4 mvp = cameraManager.getActiveCamera().getMVP(); @@ -645,7 +651,7 @@ int main(int argc, const char **argv) { { vkcv::DescriptorSetUsage( 0, core.getDescriptorSet(updateParticleVelocitiesSets[0]).vulkanHandle ) }, - vkcv::PushConstants(0) + tweakPushConstants ); core.recordBufferMemoryBarrier(cmdStream, particles.getHandle()); @@ -720,7 +726,9 @@ int main(int argc, const char **argv) { gui.beginGUI(); ImGui::Begin("Settings"); + ImGui::Checkbox("Render Grid", &renderGrid); + ImGui::SliderFloat("Alpha (PIC -> FLIP)", &alpha, 0.0f, 1.0f); ImGui::End();