diff --git a/projects/wobble_bobble/shaders/particle.inc b/projects/wobble_bobble/shaders/particle.inc
index 4572ff7fa08504d990aad94001f8214931ebdc78..00b7ab27d4e6fe205ec8c695be9cc3d35b36a7e0 100644
--- a/projects/wobble_bobble/shaders/particle.inc
+++ b/projects/wobble_bobble/shaders/particle.inc
@@ -13,4 +13,42 @@ struct Particle {
     mat4 deformation;
 };
 
+float weight_A(float x) {
+	return max(1.0f - x, 0.0f);
+}
+
+float weight_B(float x) {
+	if (x < 0.5f) {
+		return 0.75f - x * x;
+	} else
+	if (x < 1.5f) {
+		float y = (1.5f - x);
+		return 0.5f * y * y;
+	} else {
+		return 0.0f;
+	}
+}
+
+float weight_C(float x) {
+	if (x < 1.0f) {
+		return (0.5f * x - 1.0f) * x*x + 2.0f / 3.0f;
+	} else
+	if (x < 2.0f) {
+		float y = (2.0f - x);
+		return 0.5f / 3.0f * y * y * y;
+	} else {
+		return 0.0f;
+	}
+}
+
+float voxel_particle_weight(vec3 voxel, ParticleMinimal particle) {
+	if (particle.size <= 0.0f) {
+		return 0.0f;
+	}
+	
+	vec3 delta = abs(particle.position - voxel) / particle.size;
+	
+	return weight_C(delta.x) * weight_C(delta.y) * weight_C(delta.z);
+}
+
 #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 95849eee351391d0d57c2849a0359d85671d4649..49d6d962d53b56d7df10eecb9bb1ae002bad415c 100644
--- a/projects/wobble_bobble/shaders/transform_particles_to_grid.comp
+++ b/projects/wobble_bobble/shaders/transform_particles_to_grid.comp
@@ -11,34 +11,6 @@ layout(set=0, binding=0, std430) buffer particleBuffer {
 
 layout(set=0, binding=1, rgba32f) restrict writeonly uniform image3D gridImage;
 
-float weight_A(float x) {
-    return max(1.0f - x, 0.0f);
-}
-
-float weight_B(float x) {
-    if (x < 0.5f) {
-        return 0.75f - x * x;
-    } else
-    if (x < 1.5f) {
-        float y = (1.5f - x);
-        return 0.5f * y * y;
-    } else {
-        return 0.0f;
-    }
-}
-
-float weight_C(float x) {
-    if (x < 1.0f) {
-        return (0.5f * x - 1.0f) * x*x + 2.0f / 3.0f;
-    } else
-    if (x < 2.0f) {
-        float y = (2.0f - x);
-        return 0.5f / 3.0f * y * y * y;
-    } else {
-        return 0.0f;
-    }
-}
-
 #define SHARED_PARTICLES_BATCH_SIZE 64
 
 shared ParticleMinimal shared_particles [SHARED_PARTICLES_BATCH_SIZE];
@@ -64,12 +36,10 @@ void main()	{
         memoryBarrierShared();
 
         for (uint i = 0; i < SHARED_PARTICLES_BATCH_SIZE; i++) {
-            float s = shared_particles[i].size;
-            float x = distance(shared_particles[i].position, position);
-
-            if (x < 2.0f * s) {
-                gridValue += vec4(shared_particles[i].velocity, shared_particles[i].mass) * weight_C(x / s);
-            }
+            gridValue += (
+                vec4(shared_particles[i].velocity, shared_particles[i].mass) *
+                voxel_particle_weight(position, shared_particles[i])
+            );
         }
     }