aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-04-28 20:41:07 +0200
committerAdrian Kummerlaender2019-04-28 20:41:07 +0200
commitd290dcd50821308a08aed4b1bcd6087e16b0c1ed (patch)
tree0cf975057e20031f9a5f1d7ec513fc624ca15443
parentecaf665a05bdfcd10937152c378cfaec7cdf1836 (diff)
downloadcompustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.gz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.bz2
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.lz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.xz
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.tar.zst
compustream-d290dcd50821308a08aed4b1bcd6087e16b0c1ed.zip
More consistent restrictions of display values
-rw-r--r--src/main.cc16
-rw-r--r--src/shader/code/collide.glsl4
-rw-r--r--src/shader/code/extra.glsl6
-rw-r--r--src/shader/code/vertex.glsl41
4 files changed, 40 insertions, 27 deletions
diff --git a/src/main.cc b/src/main.cc
index a98ca44..8e9fa9a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -176,7 +176,7 @@ int render() {
palette_factor += 1;
}
if ( palette_factor_decr.wasClicked() ) {
- palette_factor -= 1;
+ palette_factor = std::max(1, palette_factor-1);
}
if ( window_size_changed ) {
@@ -209,7 +209,7 @@ int render() {
{
auto guard = collide_shader->use();
- collide_shader->setUniform("show_fluid_quality", display_mode == DisplayMode::QUALITY);
+ collide_shader->setUniform("show_quality", display_mode == DisplayMode::QUALITY);
collide_shader->setUniform("iT", iT);
iT += 1;
@@ -262,18 +262,18 @@ int render() {
switch ( display_mode ) {
case DisplayMode::VELOCITY:
- scene_shader->setUniform("show_fluid_quality", false);
- scene_shader->setUniform("show_curl", false);
+ scene_shader->setUniform("show_quality", false);
+ scene_shader->setUniform("show_curl", false);
fluid->draw();
break;
case DisplayMode::QUALITY:
- scene_shader->setUniform("show_fluid_quality", true);
- scene_shader->setUniform("show_curl", false);
+ scene_shader->setUniform("show_quality", true);
+ scene_shader->setUniform("show_curl", false);
fluid->draw();
break;
case DisplayMode::CURL:
- scene_shader->setUniform("show_fluid_quality", false);
- scene_shader->setUniform("show_curl", true);
+ scene_shader->setUniform("show_quality", false);
+ scene_shader->setUniform("show_curl", true);
extra->draw();
break;
}
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 191204e..d32bf78 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -11,7 +11,7 @@ uniform uint nX;
uniform uint nY;
uniform uint iT;
-uniform bool show_fluid_quality;
+uniform bool show_quality;
/// LBM constants
@@ -185,7 +185,7 @@ void main() {
d = 1.0;
}
- if ( show_fluid_quality ) {
+ if ( show_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/extra.glsl b/src/shader/code/extra.glsl
index 5ba6207..3fec976 100644
--- a/src/shader/code/extra.glsl
+++ b/src/shader/code/extra.glsl
@@ -45,8 +45,10 @@ void main() {
}
// simple central difference discretization of the 2d curl operator
- const float dxvy = (getFluidVelocity(x+1,y).y - getFluidVelocity(x-1,y).y) / (2*convLength);
- const float dyvx = (getFluidVelocity(x,y+1).x - getFluidVelocity(x,y-1).x) / (2*convLength);
+ const float dxvy = (getFluidVelocity(x+1,y).y - getFluidVelocity(x-1,y).y)
+ / (2*convLength);
+ const float dyvx = (getFluidVelocity(x,y+1).x - getFluidVelocity(x,y-1).x)
+ / (2*convLength);
setFluidExtra(x, y, dxvy - dyvx);
}
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 5136023..6ad54cf 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -10,13 +10,11 @@ out VS_OUT {
uniform uint nX;
uniform uint nY;
-uniform bool show_fluid_quality;
+uniform bool show_quality;
uniform bool show_curl;
uniform int palette_factor;
-float unit(float x) {
- return 1.0/(1.0+exp(-x));
-}
+/// Vector utilities
float sq(float x) {
return x*x;
@@ -26,6 +24,8 @@ float norm(vec2 v) {
return sqrt(sq(v.x)+sq(v.y));
}
+/// Array indexing
+
vec2 fluidVertexAtIndex(uint i) {
const float y = floor(float(i) / float(nX));
return vec2(
@@ -34,6 +34,8 @@ vec2 fluidVertexAtIndex(uint i) {
);
}
+/// Material number meaning
+
bool isInactive(int material) {
return material == 0;
}
@@ -42,6 +44,8 @@ bool isWallFrontier(int material) {
return material == 2 || material == 3;
}
+/// Data restriction
+
float restrictedQuality(float quality) {
if ( quality < 0.0 ) {
return 0.0;
@@ -50,7 +54,17 @@ float restrictedQuality(float quality) {
}
}
-vec3 trafficLightPalette(float x) {
+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));
+ }
+}
+
+/// Color palettes
+
+vec3 greenYellowRedPalette(float x) {
if ( x < 0.5 ) {
return mix(
vec3(0.0, 1.0, 0.0),
@@ -98,6 +112,8 @@ vec3 blueRedPalette(float x) {
);
}
+/// Actual vertex shader
+
void main() {
const vec2 idx = fluidVertexAtIndex(gl_VertexID);
@@ -115,19 +131,14 @@ void main() {
} else if ( isWallFrontier(material) ) {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
- if ( show_fluid_quality ) {
- vs_out.color = trafficLightPalette(
+ if ( show_quality ) {
+ vs_out.color = greenYellowRedPalette(
restrictedQuality(VertexPosition.y)
);
} else if ( show_curl ) {
- const float factor = 1.0 / float(100*palette_factor);
- if ( abs(VertexPosition.x) > 1.0 ) {
- vs_out.color = blueBlackRedPalette(
- 0.5 + (VertexPosition.x * factor)
- );
- } else {
- vs_out.color = vec3(0.0,0.0,0.0);
- }
+ vs_out.color = blueBlackRedPalette(
+ restrictedCurl(VertexPosition.x)
+ );
} else {
vs_out.color = blueRedPalette(
norm(VertexPosition.xy) / palette_factor