From e40114aad7fb5665c97c1b048515f0443cda5700 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 16 Apr 2019 23:14:06 +0200 Subject: Add flag to toggle fluid quality display e.g. check out `./compustream --size 512 128 --open --lups 300 --quality` --- src/shader/code/collide.glsl | 39 ++++++++++++++++++++++++++------------- src/shader/code/vertex.glsl | 20 +++++++++++++++----- 2 files changed, 41 insertions(+), 18 deletions(-) (limited to 'src/shader/code') 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) + ); + } } } )"; -- cgit v1.2.3