aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-12-19 19:07:05 +0100
committerAdrian Kummerlaender2018-12-19 19:07:31 +0100
commit994f70f0dd8fff208fab050a8a58f7fdf7bcfb24 (patch)
treef4cce099a3eafbc52b7dd1b8b23366c1fd8d4df9 /src
parent6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf (diff)
downloadcompustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar.gz
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar.bz2
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar.lz
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar.xz
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.tar.zst
compustream-994f70f0dd8fff208fab050a8a58f7fdf7bcfb24.zip
Tidy up external influence implementation
Diffstat (limited to 'src')
-rw-r--r--src/main.cc20
-rw-r--r--src/shader/code/collide.glsl23
2 files changed, 24 insertions, 19 deletions
diff --git a/src/main.cc b/src/main.cc
index 067af40..c19b32d 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -23,10 +23,10 @@
#include "timer.h"
-constexpr GLuint nX = 256;
-constexpr GLuint nY = 256;
+constexpr GLuint nX = 512;
+constexpr GLuint nY = 512;
-constexpr int lups = 30; // max lattice updates per second
+constexpr int lups = 50; // max lattice updates per second
float getWorldHeight(int window_width, int window_height, float world_width) {
return world_width / window_width * window_height;
@@ -56,7 +56,7 @@ int renderWindow() {
return -1;
}
- float world_width = 2*nX;
+ float world_width = 1.5*nX;
float world_height = getWorldHeight(window.getWidth(), window.getHeight(), world_width);
glm::mat4 MVP = getMVP(world_width, world_height);
@@ -123,13 +123,11 @@ int renderWindow() {
auto guard = collide_shader->use();
const auto m = window.getMouse();
- collide_shader->setUniform("mouseClicked", std::get<0>(m));
- collide_shader->setUniform("mouseX", int(
- float(std::get<1>(m)) / window.getWidth() * world_width + nX/2-1
- ));
- collide_shader->setUniform("mouseY", int(
- float(std::get<2>(m)) / window.getHeight() * world_height + nY/2
- ));
+ const float latticeMouseX = float(std::get<1>(m)) / window.getWidth() * world_width + nX/2;
+ const float latticeMouseY = float(std::get<2>(m)) / window.getHeight() * world_height + nY/2;
+
+ collide_shader->setUniform("mouseState", std::get<0>(m));
+ collide_shader->setUniform("mousePos", latticeMouseX, latticeMouseY);
collide_shader->dispatch(nX, nY);
}
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 2626c70..75bfd35 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -7,9 +7,10 @@ layout (std430, binding=1) buffer bufferCollide{ float collideCells[]; };
layout (std430, binding=2) buffer bufferStream{ float streamCells[]; };
layout (std430, binding=3) buffer bufferFluid{ float fluidCells[]; };
-uniform int mouseClicked;
-uniform int mouseX;
-uniform int mouseY;
+/// external influence
+
+uniform int mouseState;
+uniform vec2 mousePos;
/// LBM constants
@@ -97,6 +98,16 @@ vec2 velocity(uint x, uint y, float d) {
);
}
+/// Determine external influence
+
+float getExternalPressureInflux(uint x, uint y) {
+ if ( mouseState == 1 && norm(vec2(x,y) - mousePos) < 4 ) {
+ return 1.5;
+ } else {
+ return 0.0;
+ }
+}
+
/// Actual collide kernel
void main() {
@@ -107,11 +118,7 @@ void main() {
return;
}
- float d = density(x,y);
- if ( mouseClicked == 1 && abs(x - mouseX) < 3 && abs(y - mouseY) < 3 ) {
- d = 1.5;
- }
-
+ const float d = max(getExternalPressureInflux(x,y), density(x,y));
const vec2 v = velocity(x,y,d);
setFluid(x,y,v,d);