aboutsummaryrefslogtreecommitdiff
path: root/src/shader
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-04-16 23:14:06 +0200
committerAdrian Kummerlaender2019-04-16 23:14:06 +0200
commite40114aad7fb5665c97c1b048515f0443cda5700 (patch)
treede2378756b1c2a6833c5e4a5bbcca9fa57f44b5d /src/shader
parentfc02e4c5f8c8bbb014449dc27d7b69992ad6043f (diff)
downloadcompustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar.gz
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar.bz2
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar.lz
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar.xz
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.tar.zst
compustream-e40114aad7fb5665c97c1b048515f0443cda5700.zip
Add flag to toggle fluid quality display
e.g. check out `./compustream --size 512 128 --open --lups 300 --quality`
Diffstat (limited to 'src/shader')
-rw-r--r--src/shader/code/collide.glsl39
-rw-r--r--src/shader/code/vertex.glsl20
2 files changed, 41 insertions, 18 deletions
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 9ff6ab3..45e06f8 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -11,6 +11,8 @@ uniform uint nX;
uniform uint nY;
uniform uint iT;
+uniform bool fluidQuality;
+
/// Fluid characteristics
const float physCharLength = 1.0;
@@ -154,6 +156,20 @@ float getExternalMassInflux(int material) {
}
};
+float getLocalKnudsenApproximation(uint x, uint y, float d, vec2 v) {
+ float knudsen = 0.0;
+
+ for ( int i = -1; i <= 1; ++i ) {
+ for ( int j = -1; j <= 1; ++j ) {
+ const float feq = equilibrium(d,v,i,j);
+ const float fneq = get(x,y,i,j) - feq;
+ knudsen += abs(fneq / feq);
+ }
+ }
+
+ return knudsen / q;
+}
+
/// Actual collide&stream kernel
void main() {
@@ -177,29 +193,26 @@ void main() {
d = 1.0;
}
- //setFluidVelocity(x,y,v);
-
- float knudsen = 0.0;
+ if ( fluidQuality ) {
+ const float approxKn = getLocalKnudsenApproximation(x,y,d,v);
+ setFluidQuality(x,y, approxKn, int(round(log2(approxKn / Kn))));
+ } else {
+ setFluidVelocity(x,y,v);
+ }
for ( int i = -1; i <= 1; ++i ) {
for ( int j = -1; j <= 1; ++j ) {
- const float feq = equilibrium(d,v,i,j);
- const float fneq = get(x,y,i,j) - feq;
- knudsen += abs(fneq / feq);
-
- set(x+i,y+j,i,j, get(x,y,i,j) + relaxationFrequency * (feq - get(x,y,i,j)));
+ set(x+i,y+j,i,j,
+ get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
}
}
-
- knudsen /= q;
-
- setFluidQuality(x,y,knudsen,int(round(log2(knudsen / Kn))));
}
if ( isBounceBackCell(material) ) {
for ( int i = -1; i <= 1; ++i ) {
for ( int j = -1; j <= 1; ++j ) {
- set(x+(-1)*i,y+(-1)*j,(-1)*i,(-1)*j, get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
+ set(x+(-1)*i,y+(-1)*j,(-1)*i,(-1)*j,
+ get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
}
}
}
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 7851292..8958600 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -10,6 +10,8 @@ out VS_OUT {
uniform uint nX;
uniform uint nY;
+uniform bool fluidQuality;
+
const float velocityDisplayAmplifier = 3.0;
const int qualityDisplayRestrictor = 6;
@@ -66,11 +68,19 @@ void main() {
} else if ( isWallFrontier(material) ) {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
- vs_out.color = mix(
- vec3(0.0, 1.0, 0.0),
- vec3(1.0, 0.0, 0.0),
- restrictedQuality(VertexPosition.y)
- );
+ if ( fluidQuality ) {
+ vs_out.color = mix(
+ vec3(0.0, 1.0, 0.0),
+ vec3(1.0, 0.0, 0.0),
+ 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)
+ );
+ }
}
}
)";