From 978581caf40260b707b851b93b26b47b6445d773 Mon Sep 17 00:00:00 2001
From: Josh Morgenstern <josh@morgenstern.dev>
Date: Mon, 13 Sep 2021 17:12:06 +0200
Subject: [PATCH] [#111] add boundary constraints

---
 projects/sph/shaders/updateData.comp | 39 +++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/projects/sph/shaders/updateData.comp b/projects/sph/shaders/updateData.comp
index c80b1e1a..38541cda 100644
--- a/projects/sph/shaders/updateData.comp
+++ b/projects/sph/shaders/updateData.comp
@@ -1,7 +1,7 @@
 #version 450 core
 #extension GL_ARB_separate_shader_objects : enable
 
-#define absorbtion 0.9
+#define ABSORBTION 0.9
 #define dt 0.0003
 
 layout(local_size_x = 256) in;
@@ -44,6 +44,43 @@ void main() {
     vec3 vel_new = inParticle[id].velocity + dt * accel;
     vec3 pos_new = inParticle[id].position + dt * vel_new;
 
+    // Überprüfe Randbedingungen x
+    if (inParticle[id].position.x < -0.6)
+    {
+        vel_new.x *= -ABSORBTION;
+        pos_new.x = -0.6;
+    }
+    else if (inParticle[id].position.x > 0.6)
+    {
+        vel_new.x *= -ABSORBTION;
+        pos_new.x = 0.6;
+    }
+
+    // Überprüfe Randbedingungen y
+    if (inParticle[id].position.y < -0.8)
+    {
+        vel_new.y *= -ABSORBTION;
+        pos_new.y = -0.8;
+
+    }
+    else if (inParticle[id].position.y > 0.8)
+    {
+        vel_new.y *= -ABSORBTION;
+        pos_new.y = 0.8;
+    }
+
+    // Überprüfe Randbedingungen z
+    if (inParticle[id].position.z < -0.6 )
+    {
+        vel_new.z *= -ABSORBTION;
+        pos_new.z = -0.6;
+    }
+    else if (inParticle[id].position.z > 0.6 )
+    {
+        vel_new.z *= -ABSORBTION;
+        pos_new.z = 0.6;
+    }
+
     outParticle[id].force = inParticle[id].force;
     outParticle[id].density = inParticle[id].density;
     outParticle[id].pressure = inParticle[id].pressure;
-- 
GitLab