From 40f5932dc296651753d303dd181990f73a39501d Mon Sep 17 00:00:00 2001 From: Josh Morgenstern <josh@morgenstern.dev> Date: Wed, 22 Sep 2021 15:41:29 +0200 Subject: [PATCH] [#111] add params in push constant to updateData shader --- projects/sph/shaders/updateData.comp | 56 +++++++++++++++++++--------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/projects/sph/shaders/updateData.comp b/projects/sph/shaders/updateData.comp index 7215147e..3c935b23 100644 --- a/projects/sph/shaders/updateData.comp +++ b/projects/sph/shaders/updateData.comp @@ -2,8 +2,6 @@ #extension GL_ARB_separate_shader_objects : enable #extension GL_GOOGLE_include_directive : enable -#include "particle_params.inc" - layout(local_size_x = 256) in; struct Particle @@ -28,11 +26,20 @@ layout(std430, binding = 1) writeonly buffer buffer_outParticle }; layout( push_constant ) uniform constants{ - float deltaTime; + float h; + float mass; + float gasConstant; + float offset; + float gravity; + float viscosity; + float ABSORBTION; + float dt; + vec3 gravityDir; float particleCount; }; void main() { + uint id = gl_GlobalInvocationID.x; if(id >= int(particleCount)) @@ -42,48 +49,61 @@ void main() { vec3 accel = inParticle[id].force / inParticle[id].density; vec3 vel_new = inParticle[id].velocity + (dt * accel); + + vec3 out_force = inParticle[id].force; + float out_density = inParticle[id].density; + float out_pressure = inParticle[id].pressure; + + if (length(vel_new) > 100.f) + { + vel_new = normalize(vel_new)*50; + out_density = 0.01f; + out_pressure = 0.01f; + out_force = gravity * vec3(-gravityDir.x,gravityDir.y,gravityDir.z); + } + vec3 pos_new = inParticle[id].position + (dt * vel_new); // Überprüfe Randbedingungen x if (inParticle[id].position.x < -1.0) { - vel_new.x *= -ABSORBTION; - pos_new.x = -1.0; + vel_new = reflect(vel_new.xyz, vec3(1.f,0.f,0.f)) * ABSORBTION; + pos_new.x = -1.0 + 0.01f; } else if (inParticle[id].position.x > 1.0) { - vel_new.x *= -ABSORBTION; - pos_new.x = 1.0; + vel_new = reflect(vel_new,vec3(1.f,0.f,0.f)) * ABSORBTION; + pos_new.x = 1.0 - 0.01f; } // Überprüfe Randbedingungen y if (inParticle[id].position.y < -1.0) { - vel_new.y *= -ABSORBTION; - pos_new.y = -1.0; + vel_new = reflect(vel_new,vec3(0.f,1.f,0.f)) * ABSORBTION; + pos_new.y = -1.0 + 0.01f; } else if (inParticle[id].position.y > 1.0) { - vel_new.y *= -ABSORBTION; - pos_new.y = 1.0; + vel_new = reflect(vel_new,vec3(0.f,1.f,0.f)) * ABSORBTION; + pos_new.y = 1.0 - 0.01f; } // Überprüfe Randbedingungen z if (inParticle[id].position.z < -1.0 ) { - vel_new.z *= -ABSORBTION; - pos_new.z = -1.0; + vel_new = reflect(vel_new,vec3(0.f,0.f,1.f)) * ABSORBTION; + pos_new.z = -1.0 + 0.01f; } else if (inParticle[id].position.z > 1.0 ) { - vel_new.z *= -ABSORBTION; - pos_new.z = 1.0; + vel_new = reflect(vel_new,vec3(0.f,0.f,1.f)) * ABSORBTION; + pos_new.z = 1.0 - 0.01f; } - outParticle[id].force = inParticle[id].force; - outParticle[id].density = inParticle[id].density; - outParticle[id].pressure = inParticle[id].pressure; + outParticle[id].force = out_force; + outParticle[id].density = out_density; + outParticle[id].pressure = out_pressure; outParticle[id].position = pos_new; outParticle[id].velocity = vel_new; } -- GitLab