From 06f5d24cf261602e40b7cfb424ede43dc2efe2d6 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Sat, 29 Jan 2022 20:44:16 +0100
Subject: [PATCH] Avoid division by zero

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 .../wobble_bobble/shaders/transform_particles_to_grid.comp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp
index ce8ee02b..95849eee 100644
--- a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp
+++ b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp
@@ -64,10 +64,11 @@ void main()	{
         memoryBarrierShared();
 
         for (uint i = 0; i < SHARED_PARTICLES_BATCH_SIZE; i++) {
-            float x = distance(shared_particles[i].position, position) / shared_particles[i].size;
+            float s = shared_particles[i].size;
+            float x = distance(shared_particles[i].position, position);
 
-            if (x < 2.0f) {
-                gridValue += vec4(shared_particles[i].velocity, shared_particles[i].mass) * weight_C(x);
+            if (x < 2.0f * s) {
+                gridValue += vec4(shared_particles[i].velocity, shared_particles[i].mass) * weight_C(x / s);
             }
         }
     }
-- 
GitLab