aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/glfw/window.cc1
-rw-r--r--src/main.cc34
-rw-r--r--src/shader/code/collide.glsl14
-rw-r--r--src/shader/code/extra.glsl2
-rw-r--r--src/shader/code/vertex.glsl2
5 files changed, 29 insertions, 24 deletions
diff --git a/src/glfw/window.cc b/src/glfw/window.cc
index 77be947..c0074ad 100644
--- a/src/glfw/window.cc
+++ b/src/glfw/window.cc
@@ -14,7 +14,6 @@ Window::Window(const std::string& title):
_handle(glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL)) {
if ( _handle != nullptr ) {
glfwMakeContextCurrent(_handle);
- glfwSwapInterval(0);
if ( glewInit() == GLEW_OK ) {
_good = true;
}
diff --git a/src/main.cc b/src/main.cc
index 8e9fa9a..7d2ebe8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -24,7 +24,7 @@
#include "timer.h"
-GLuint maxLUPS = 100;
+GLuint maxLUPF = 100;
GLuint nX = 512;
GLuint nY = 256;
@@ -184,25 +184,19 @@ int render() {
MVP = getMVP(world_width, world_height);
}
- if ( update_lattice && timer::millisecondsSince(last_lattice_update) >= 1000/maxLUPS ) {
+ if ( update_lattice ) {
if ( timer::secondsSince(last_lups_update) >= 1.0 ) {
- std::cout << "\rComputing about " << statLUPS << " lattice updates per second." << std::flush;
+ std::cout << "\r~ " << nX*nY * statLUPS / timer::secondsSince(last_lups_update) * 1e-6 << " MLUPS" << std::flush;
statLUPS = 0;
last_lups_update = timer::now();
}
- statLUPS += 1;
-
if ( tick ) {
interact_shader->workOn(tick_buffers);
- collide_shader->workOn(tick_buffers);
extra_shader->workOn(tick_buffers);
- tick = false;
} else {
interact_shader->workOn(tock_buffers);
- collide_shader->workOn(tock_buffers);
extra_shader->workOn(tock_buffers);
- tick = true;
}
/// Perform collide & stream steps
@@ -213,7 +207,19 @@ int render() {
collide_shader->setUniform("iT", iT);
iT += 1;
- collide_shader->dispatch(nX, nY);
+ for (auto i=0; i < maxLUPF; ++i) {
+ if ( tick ) {
+ collide_shader->workOn(tick_buffers);
+ tick = false;
+ } else {
+ collide_shader->workOn(tock_buffers);
+ tick = true;
+ }
+
+ collide_shader->dispatch(nX, nY);
+ }
+
+ statLUPS += maxLUPF;
}
if ( display_mode == DisplayMode::CURL ) {
@@ -289,18 +295,18 @@ bool parseArguments(int argc, char* argv[]) {
for ( int i = 1; i < argc; ++i ) {
const auto& arg = std::string_view(argv[i]);
- if ( arg == "--lups" ) {
+ if ( arg == "--lupf" ) {
if ( i+1 < argc ) {
try {
i += 1;
- maxLUPS = std::stoi(argv[i]);
+ maxLUPF = std::stoi(argv[i]);
}
catch ( std::invalid_argument& ex ) {
- std::cerr << "Maximum lattice updates per second malformed." << std::endl;
+ std::cerr << "Maximum lattice updates per frame malformed." << std::endl;
return false;
}
} else {
- std::cerr << "Maximum lattice updates per second undefined." << std::endl;
+ std::cerr << "Maximum lattice updates per frame undefined." << std::endl;
return false;
}
}
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 0f9b2bd..ef1ba93 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -1,7 +1,7 @@
static const std::string COLLIDE_SHADER_CODE = R"(
#version 430
-layout (local_size_x = 1, local_size_y = 1) in;
+layout (local_size_x = 32, local_size_y = 1) in;
layout (std430, binding=1) buffer bufferCollide { float collideCells[]; };
layout (std430, binding=2) buffer bufferStream { float streamCells[]; };
@@ -32,7 +32,7 @@ const float latticeCharVelocity = 0.005;
/// Unit conversion
-const float resolution = max(nX,nY);
+const float resolution = min(nX,nY);
const float convLength = physCharLength / resolution;
const float convTime = latticeCharVelocity / physCharVelocity * physCharLength / resolution;
const float convVelocity = convLength / convTime;
@@ -110,7 +110,7 @@ int getMaterial(uint x, uint y) {
float density(uint x, uint y) {
const uint idx = indexOfLatticeCell(x, y);
- float d = 0.;
+ float d = 0.f;
for ( int i = 0; i < q; ++i ) {
d += collideCells[idx + i];
}
@@ -118,7 +118,7 @@ float density(uint x, uint y) {
}
vec2 velocity(uint x, uint y, float d) {
- return 1./d * vec2(
+ return 1.f/d * vec2(
get(x,y, 1, 0) - get(x,y,-1, 0) + get(x,y, 1, 1) - get(x,y,-1,-1) + get(x,y, 1,-1) - get(x,y,-1,1),
get(x,y, 0, 1) - get(x,y, 0,-1) + get(x,y, 1, 1) - get(x,y,-1,-1) - get(x,y, 1,-1) + get(x,y,-1,1)
);
@@ -127,7 +127,7 @@ vec2 velocity(uint x, uint y, float d) {
/// Equilibrium distribution
float equilibrium(float d, vec2 v, int i, int j) {
- return w(i,j) * d * (1 + 3*comp(i,j,v) + 4.5*sq(comp(i,j,v)) - 1.5*sq(norm(v)));
+ return w(i,j) * d * (1.f + 3.f*comp(i,j,v) + 4.5f*sq(comp(i,j,v)) - 1.5f*sq(norm(v)));
}
/// Material number meaning (geometry is only changed by the interaction shader)
@@ -179,10 +179,10 @@ void main() {
if ( isBulkFluidCell(material) ) {
if ( isInflowCell(material) ) {
- v = vec2(min(float(iT)/5000.0*latticeCharVelocity, latticeCharVelocity), 0.0);
+ v = vec2(min(float(iT)/100.f*latticeCharVelocity, latticeCharVelocity), 0.f);
}
if ( isOutflowCell(material) ) {
- d = 1.0;
+ d = 1.f;
}
if ( show_quality ) {
diff --git a/src/shader/code/extra.glsl b/src/shader/code/extra.glsl
index b8483ae..4b149fb 100644
--- a/src/shader/code/extra.glsl
+++ b/src/shader/code/extra.glsl
@@ -9,7 +9,7 @@ layout (std430, binding=4) buffer bufferExtra { float extraCells[]; };
uniform uint nX;
uniform uint nY;
-const float convLength = 1.0 / float(max(nX,nY));
+const float convLength = 1.0 / float(min(nX,nY));
/// Array indexing
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 6ad54cf..10abf0c 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -58,7 +58,7 @@ float restrictedCurl(float curl) {
if ( abs(curl) < 1.0 ) {
return 0.5;
} else {
- return 0.5 + 0.5*min(1.0, curl / (50*palette_factor));
+ return 0.5 + 0.5*min(1.0, curl / sq(palette_factor));
}
}