diff options
author | Adrian Kummerlaender | 2019-02-23 16:10:08 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2019-02-23 16:10:08 +0100 |
commit | 389da8159978571e8156ff7692bc595d957e846e (patch) | |
tree | bd40ebff4b5f917a2d25ce76b973709922aa7b59 /src/shader/code | |
parent | 9779fd7484f7af6d10ae28ca3763c6d938c341e3 (diff) | |
download | compustream-389da8159978571e8156ff7692bc595d957e846e.tar compustream-389da8159978571e8156ff7692bc595d957e846e.tar.gz compustream-389da8159978571e8156ff7692bc595d957e846e.tar.bz2 compustream-389da8159978571e8156ff7692bc595d957e846e.tar.lz compustream-389da8159978571e8156ff7692bc595d957e846e.tar.xz compustream-389da8159978571e8156ff7692bc595d957e846e.tar.zst compustream-389da8159978571e8156ff7692bc595d957e846e.zip |
Store material in fluid buffer and improve visualization
Replaces the density value which is actually not that useful for visualization.
Encoding integer values as floats by casting and comparing them using
exact floating point comparison is not very safe but works out for now.
Diffstat (limited to 'src/shader/code')
-rw-r--r-- | src/shader/code/collide.glsl | 36 | ||||
-rw-r--r-- | src/shader/code/stream.glsl | 21 | ||||
-rw-r--r-- | src/shader/code/vertex.glsl | 16 |
3 files changed, 36 insertions, 37 deletions
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl index 182f5bd..3f4e2c5 100644 --- a/src/shader/code/collide.glsl +++ b/src/shader/code/collide.glsl @@ -6,7 +6,6 @@ layout (local_size_x = 1, local_size_y = 1) in; layout (std430, binding=1) buffer bufferCollide { float collideCells[]; }; layout (std430, binding=2) buffer bufferStream { float streamCells[]; }; layout (std430, binding=3) buffer bufferFluid { float fluidCells[]; }; -layout (std430, binding=4) buffer bufferGeometry { int materialCells[]; }; /// external influence @@ -70,29 +69,22 @@ void set(uint x, uint y, int i, int j, float v) { collideCells[indexOfLatticeCell(x,y) + indexOfDirection(i,j)] = v; } -void setFluid(uint x, uint y, vec2 v, float d) { +void setFluid(uint x, uint y, vec2 v) { const uint idx = indexOfFluidVertex(x, y); fluidCells[idx + 0] = v.x; fluidCells[idx + 1] = v.y; - fluidCells[idx + 2] = d; } int getMaterial(uint x, uint y) { - return materialCells[nX*y + x]; + const uint idx = indexOfFluidVertex(x, y); + return int(fluidCells[idx + 2]); } void setMaterial(uint x, uint y, int m) { - materialCells[nX*y + x] = m; -} - -void disableFluid(uint x, uint y) { const uint idx = indexOfFluidVertex(x, y); - fluidCells[idx + 0] = 0.0; - fluidCells[idx + 1] = 0.0; - fluidCells[idx + 2] = -2.0; + fluidCells[idx + 2] = m; } - /// Moments float density(uint x, uint y) { @@ -125,7 +117,7 @@ void disableWallInterior(uint x, uint y) { for ( int i = -1; i <= 1; ++i ) { for ( int j = -1; j <= 1; ++j ) { const int material = getMaterial(x+i,y+j); - if ( material == 0 || material == 2 ) { + if ( material == 0 || material == 2 || material == 3 ) { ++wallNeighbors; } } @@ -139,7 +131,7 @@ void disableWallInterior(uint x, uint y) { /// Determine external influence float getExternalPressureInflux(uint x, uint y) { - if ( mouseState == 1 && norm(vec2(x,y) - mousePos) < 3 ) { + if ( mouseState == 1 && norm(vec2(x,y) - mousePos) < 2 ) { return 1.5; } else { return 0.0; @@ -147,7 +139,7 @@ float getExternalPressureInflux(uint x, uint y) { } bool isWallRequestedAt(uint x, uint y) { - if ( mouseState == 2 && norm(vec2(x,y) - mousePos) < 3 ) { + if ( mouseState == 2 && norm(vec2(x,y) - mousePos) < 2 ) { return true; } else { return false; @@ -164,14 +156,14 @@ void main() { return; } - if ( isWallRequestedAt(x,y) ) { - setMaterial(x,y,2); - disableFluid(x,y); - } - const int material = getMaterial(x,y); - if ( material == 2 ) { // wall + if ( isWallRequestedAt(x,y) && material == 1 ) { + setMaterial(x,y,3); + return; + } + + if ( material == 3 ) { // manually added wall disableWallInterior(x,y); } @@ -179,7 +171,7 @@ void main() { const float d = max(getExternalPressureInflux(x,y), density(x,y)); const vec2 v = velocity(x,y,d); - setFluid(x,y,v,d); + setFluid(x,y,v); for ( int i = -1; i <= 1; ++i ) { for ( int j = -1; j <= 1; ++j ) { diff --git a/src/shader/code/stream.glsl b/src/shader/code/stream.glsl index a8aec1d..59aed98 100644 --- a/src/shader/code/stream.glsl +++ b/src/shader/code/stream.glsl @@ -5,7 +5,7 @@ layout (local_size_x = 1, local_size_y = 1) in; layout (std430, binding=1) buffer bufferCollide { float collideCells[]; }; layout (std430, binding=2) buffer bufferStream { float streamCells[]; }; -layout (std430, binding=4) buffer bufferGeometry { int materialCells[]; }; +layout (std430, binding=3) buffer bufferFluid { float fluidCells[]; }; /// LBM constants @@ -24,6 +24,10 @@ uint indexOfLatticeCell(uint x, uint y) { return q*nX*y + q*x; } +uint indexOfFluidVertex(uint x, uint y) { + return 3*nX*y + 3*x; +} + /// Data access float get(uint x, uint y, int i, int j) { @@ -35,17 +39,8 @@ void set(uint x, uint y, int i, int j, float v) { } int getMaterial(uint x, uint y) { - return materialCells[nX*y + x]; -} - -/// Domain description - -bool isEndOfWorld(uint x, uint y) { - return x == 0 || x == nX-1 || y == 0 || y == nY-1; -} - -bool isOuterWall(uint x, uint y) { - return x == 1 || x == nX-2 || y == 1 || y == nY-2; + const uint idx = indexOfFluidVertex(x, y); + return int(fluidCells[idx + 2]); } /// Boundary conditions @@ -74,7 +69,7 @@ void main() { return; } - if ( material == 2 ) { + if ( material == 2 || material == 3 ) { bounceBack(x,y); } diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl index 69bbaef..e0ce9a8 100644 --- a/src/shader/code/vertex.glsl +++ b/src/shader/code/vertex.glsl @@ -32,6 +32,14 @@ vec2 fluidVertexAtIndex(uint i) { ); } +bool isInactive(int material) { + return material == 0; +} + +bool isWallFrontier(int material) { + return material == 2 || material == 3; +} + void main() { const vec2 idx = fluidVertexAtIndex(gl_VertexID); @@ -42,13 +50,17 @@ void main() { 1. ); - if ( VertexPosition.z < -1.0 ) { + const int material = int(round(VertexPosition.z)); + + if ( isInactive(material) ) { + vs_out.color = vec3(0.5, 0.5, 0.5); + } else if ( isWallFrontier(material) ) { vs_out.color = vec3(0.0, 0.0, 0.0); } else { vs_out.color = mix( vec3(-0.5, 0.0, 1.0), vec3( 1.0, 0.0, 0.0), - displayAmplifier * VertexPosition.z * norm(VertexPosition.xy) + displayAmplifier * norm(VertexPosition.xy) ); } } |