aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cc51
-rw-r--r--src/shader/code/collide.glsl24
-rw-r--r--src/shader/code/vertex.glsl12
3 files changed, 42 insertions, 45 deletions
diff --git a/src/main.cc b/src/main.cc
index 92f6f2a..c69bbe1 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -26,8 +26,6 @@
GLuint maxLUPS = 100;
GLuint nX = 512;
GLuint nY = 256;
-bool open_boundaries = false;
-bool show_fluid_quality = false;
float getWorldHeight(int window_width, int window_height, float world_width) {
return world_width / window_width * window_height;
@@ -49,17 +47,6 @@ glm::mat4 getMVP(float world_width, float world_height) {
return projection * view;
}
-int setupPlainGeometry(int x, int y) {
- if ( x == 0 || y == 0 || x == nX-1 || y == nY-1 ) {
- return 0; // disable end of world
- }
- if ( ((x == 1 || x == nX-2) && (y > 0 && y < nY-1))
- || ((y == 1 || y == nY-2) && (x > 0 && x < nX-1)) ) {
- return 2; // bounce back outer walls
- }
- return 1; // everything else shall be bulk fluid
-}
-
int setupOpenGeometry(int x, int y) {
if ( x == 0 || y == 0 || x == nX-1 || y == nY-1 ) {
return 0; // disable end of world
@@ -107,7 +94,7 @@ int render() {
lattice_a = std::make_unique<LatticeCellBuffer>(nX, nY);
lattice_b = std::make_unique<LatticeCellBuffer>(nX, nY);
- fluid = std::make_unique< FluidCellBuffer>(nX, nY, open_boundaries ? setupOpenGeometry : setupPlainGeometry);
+ fluid = std::make_unique< FluidCellBuffer>(nX, nY, setupOpenGeometry);
interact_shader = std::make_unique<ComputeShader>(INTERACT_SHADER_CODE);
collide_shader = std::make_unique<ComputeShader>(COLLIDE_SHADER_CODE);
@@ -118,10 +105,15 @@ int render() {
return -1;
}
+ auto pause_key = window.getKeyWatcher(GLFW_KEY_SPACE);
bool update_lattice = true;
- bool tick = true;
- auto pause_key = window.getKeyWatcher(GLFW_KEY_SPACE);
+ auto toggle_key = window.getKeyWatcher(GLFW_KEY_T);
+ bool show_fluid_quality = false;
+
+ auto palette_factor_incr = window.getKeyWatcher(GLFW_KEY_UP);
+ auto palette_factor_decr = window.getKeyWatcher(GLFW_KEY_DOWN);
+ int palette_factor = 6;
int prevMouseState = 0;
float prevLatticeMouseX;
@@ -140,11 +132,25 @@ int render() {
auto last_lattice_update = timer::now();
auto last_lups_update = timer::now();
+ bool tick = true;
+
window.render([&](bool window_size_changed) {
if ( pause_key.wasClicked() ) {
update_lattice = !update_lattice;
}
+ if ( toggle_key.wasClicked() ) {
+ show_fluid_quality = !show_fluid_quality;
+ }
+
+ if ( palette_factor_incr.wasClicked() ) {
+ palette_factor += 1;
+ }
+
+ if ( palette_factor_decr.wasClicked() ) {
+ palette_factor -= 1;
+ }
+
if ( window_size_changed ) {
world_height = getWorldHeight(window.getWidth(), window.getHeight(), world_width);
MVP = getMVP(world_width, world_height);
@@ -173,7 +179,7 @@ int render() {
{
auto guard = collide_shader->use();
- collide_shader->setUniform("fluidQuality", show_fluid_quality);
+ collide_shader->setUniform("show_fluid_quality", show_fluid_quality);
collide_shader->setUniform("iT", iT);
iT += 1;
@@ -215,7 +221,8 @@ int render() {
scene_shader->setUniform("MVP", MVP);
scene_shader->setUniform("nX", nX);
scene_shader->setUniform("nY", nY);
- scene_shader->setUniform("fluidQuality", show_fluid_quality);
+ scene_shader->setUniform("show_fluid_quality", show_fluid_quality);
+ scene_shader->setUniform("palette_factor", palette_factor);
glClear(GL_COLOR_BUFFER_BIT);
fluid->draw();
@@ -264,14 +271,6 @@ bool parseArguments(int argc, char* argv[]) {
return false;
}
}
-
- if ( arg == "--open" ) {
- open_boundaries = true;
- }
-
- if ( arg == "--quality" ) {
- show_fluid_quality = true;
- }
}
return true;
}
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index d3d004d..d877634 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -11,13 +11,14 @@ uniform uint nX;
uniform uint nY;
uniform uint iT;
-uniform bool fluidQuality;
+uniform bool show_fluid_quality;
/// Fluid characteristics
const float physCharLength = 1.0;
const float physCharVelocity = 1.0;
-const float physViscosity = 0.1;
+const float physViscosity = 0.01;
+const float latticeCharVelocity = 0.01;
/// LBM constants
@@ -29,17 +30,16 @@ const float weight[q] = float[](
);
const float invCs2 = 1./3.;
-const float relaxationTime = 0.6;
-const float relaxationFrequency = 1 / relaxationTime;
-
/// Unit conversion
-const float convLength = physCharLength / max(nX,nY);
-const float convTime = (relaxationTime - 0.5) / invCs2 * convLength*convLength / physViscosity;
+const float resolution = max(nX,nY);
+const float convLength = physCharLength / resolution;
+const float convTime = latticeCharVelocity / physCharVelocity * physCharLength / resolution;
const float convVelocity = convLength / convTime;
const float convViscosity = convLength * convLength / convTime;
-const float latticeCharVelocity = physCharVelocity / convVelocity;
+const float relaxationTime = physViscosity / convViscosity * invCs2 + 0.5;
+const float relaxationFrequency = 1 / relaxationTime;
/// Emergent fluid numbers
@@ -91,8 +91,8 @@ void set(uint x, uint y, int i, int j, float v) {
void setFluidVelocity(uint x, uint y, vec2 v) {
const uint idx = indexOfFluidVertex(x, y);
- fluidCells[idx + 0] = v.x;
- fluidCells[idx + 1] = v.y;
+ fluidCells[idx + 0] = v.x*convVelocity;
+ fluidCells[idx + 1] = v.y*convVelocity;
}
void setFluidQuality(uint x, uint y, float knudsen, int quality) {
@@ -187,13 +187,13 @@ void main() {
if ( isBulkFluidCell(material) ) {
if ( isInflowCell(material) ) {
- d = min(1.0+float(iT)*0.2/1000.0, 1.2);
+ v = vec2(min(float(iT)/5000.0*latticeCharVelocity, latticeCharVelocity), 0.0);
}
if ( isOutflowCell(material) ) {
d = 1.0;
}
- if ( fluidQuality ) {
+ if ( show_fluid_quality ) {
const float approxKn = getLocalKnudsenApproximation(x,y,d,v);
setFluidQuality(x,y, approxKn, int(round(log2(approxKn / Kn))));
} else {
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index e64a983..0f0e07c 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -10,10 +10,8 @@ out VS_OUT {
uniform uint nX;
uniform uint nY;
-uniform bool fluidQuality;
-
-const float velocityDisplayAmplifier = 3.0;
-const int qualityDisplayRestrictor = 6;
+uniform bool show_fluid_quality;
+uniform int palette_factor;
float unit(float x) {
return 1.0/(1.0+exp(-x));
@@ -47,7 +45,7 @@ float restrictedQuality(float quality) {
if ( quality < 0.0 ) {
return 0.0;
} else {
- return min(1.0, quality / qualityDisplayRestrictor);
+ return min(1.0, quality / palette_factor);
}
}
@@ -84,13 +82,13 @@ void main() {
} else if ( isWallFrontier(material) ) {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
- if ( fluidQuality ) {
+ if ( show_fluid_quality ) {
vs_out.color = trafficLightPalette(restrictedQuality(VertexPosition.y));
} else {
vs_out.color = mix(
vec3(-0.5, 0.0, 1.0),
vec3( 1.0, 0.0, 0.0),
- velocityDisplayAmplifier * norm(VertexPosition.xy)
+ norm(VertexPosition.xy) / float(palette_factor)
);
}
}