From ede5386d53a453cb56c9b1c80de0a80322ddc6f1 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 Dec 2018 19:09:25 +0100 Subject: Try out velocity norm color mapping --- src/buffer/vertex/fluid_cell_buffer.h | 5 ++--- src/buffer/vertex/lattice_cell_buffer.cc | 19 ++++++++++--------- src/buffer/vertex/lattice_cell_buffer.h | 4 ---- src/shader/code/collide.glsl | 32 ++++++++++++++++---------------- src/shader/code/geometry.glsl | 10 ++++------ src/shader/code/vertex.glsl | 10 +++++++++- 6 files changed, 41 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/buffer/vertex/fluid_cell_buffer.h b/src/buffer/vertex/fluid_cell_buffer.h index f71c2cb..9e535cb 100644 --- a/src/buffer/vertex/fluid_cell_buffer.h +++ b/src/buffer/vertex/fluid_cell_buffer.h @@ -1,12 +1,11 @@ #pragma once -#include - #include class FluidCellBuffer { private: - std::vector _data; + const GLuint _nX; + const GLuint _nY; GLuint _array; GLuint _buffer; diff --git a/src/buffer/vertex/lattice_cell_buffer.cc b/src/buffer/vertex/lattice_cell_buffer.cc index c2b877b..ea4e103 100644 --- a/src/buffer/vertex/lattice_cell_buffer.cc +++ b/src/buffer/vertex/lattice_cell_buffer.cc @@ -1,19 +1,20 @@ #include "lattice_cell_buffer.h" -#include +#include -LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY): - _data(9*nX*nY, GLfloat{1./9.}) { +LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY) { glGenVertexArrays(1, &_array); glGenBuffers(1, &_buffer); - const int inset = 0.4*nX; + std::vector data(9*nX*nY, GLfloat{1./9.}); + const int insetX = 0.45*nX; + const int insetY = 0.45*nY; - for (int x = inset; x < nX-inset; x++) { - for (int y = inset; y < nY-inset; y++) { + for (int x = insetX; x < nX-insetX; x++) { + for (int y = insetY; y < nY-insetY; y++) { for ( int i = -1; i <= 1; ++i ) { for ( int j = -1; j <= 1; ++j ) { - _data[9*nX*y + 9*x + (i+1)*3 + j+1] = 1./64.; + data[9*nX*y + 9*x + (i+1)*3 + j+1] = 0.5; } } } @@ -23,8 +24,8 @@ LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY): glBindBuffer(GL_ARRAY_BUFFER, _buffer); glBufferData( GL_ARRAY_BUFFER, - _data.size() * sizeof(GLfloat), - _data.data(), + data.size() * sizeof(GLfloat), + data.data(), GL_DYNAMIC_DRAW ); diff --git a/src/buffer/vertex/lattice_cell_buffer.h b/src/buffer/vertex/lattice_cell_buffer.h index f6638c8..e5e00a4 100644 --- a/src/buffer/vertex/lattice_cell_buffer.h +++ b/src/buffer/vertex/lattice_cell_buffer.h @@ -1,13 +1,9 @@ #pragma once -#include - #include class LatticeCellBuffer { private: - std::vector _data; - GLuint _array; GLuint _buffer; diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl index 3982ad8..f960dcd 100644 --- a/src/shader/code/collide.glsl +++ b/src/shader/code/collide.glsl @@ -13,7 +13,19 @@ uniform uint nY; const uint q = 9; const float omega = 0.6; -const float displayAmplifier = 1000.; +const float displayAmplifier = 10.; + +float comp(int x, int y, vec2 v) { + return x*v.x + y*v.y; +} + +float sq(float x) { + return x*x; +} + +float norm(vec2 v) { + return sqrt(sq(v.x)+sq(v.y)); +} float get(uint x, uint y, int i, int j) { return collideCells[q*nX*y + q*x + (i+1)*3 + j+1]; @@ -24,9 +36,9 @@ void set(uint x, uint y, int i, int j, float v) { } void setFluid(uint x, uint y, vec2 v, float d) { - fluidCells[3*nX*y + 3*x + 0] = float(x)-nX/2 + displayAmplifier*v.x; - fluidCells[3*nX*y + 3*x + 1] = float(y)-nY/2 + displayAmplifier*v.y; - fluidCells[3*nX*y + 3*x + 2] = d; + fluidCells[3*nX*y + 3*x + 0] = float(x)-nX/2;// + displayAmplifier*v.x; + fluidCells[3*nX*y + 3*x + 1] = float(y)-nY/2;// + displayAmplifier*v.y; + fluidCells[3*nX*y + 3*x + 2] = displayAmplifier * norm(v); } float density(uint x, uint y) { @@ -70,18 +82,6 @@ float w(int i, int j) { } } -float comp(int x, int y, vec2 v) { - return x*v.x + y*v.y; -} - -float sq(float x) { - return x*x; -} - -float norm(vec2 v) { - return sqrt(sq(v.x)+sq(v.y)); -} - void main() { const uint x = gl_GlobalInvocationID.x; const uint y = gl_GlobalInvocationID.y; diff --git a/src/shader/code/geometry.glsl b/src/shader/code/geometry.glsl index 6ecfc99..e74d52f 100644 --- a/src/shader/code/geometry.glsl +++ b/src/shader/code/geometry.glsl @@ -17,7 +17,7 @@ vec4 project(vec4 v) { } void emitSquareAt(vec4 position) { - const float size = 0.2; + const float size = 0.5; gl_Position = project(position + vec4(-size, -size, 0.0, 0.0)); EmitVertex(); @@ -30,10 +30,8 @@ void emitSquareAt(vec4 position) { } void main() { - if ( gl_in[0].gl_Position.xyz != vec3(0.,0.,0.) ) { - color = gs_in[0].color; - emitSquareAt(gl_in[0].gl_Position); - EndPrimitive(); - } + color = gs_in[0].color; + emitSquareAt(gl_in[0].gl_Position); + EndPrimitive(); } )"; diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl index 453b6fa..516f2c6 100644 --- a/src/shader/code/vertex.glsl +++ b/src/shader/code/vertex.glsl @@ -7,8 +7,16 @@ out VS_OUT { vec3 color; } vs_out; +float unit(float x) { + return 1.0/(1.0+exp(-x)); +} + +vec3 getColor(float x) { + return x*vec3(1.0,0.0,0.0) + (1-x)*vec3(-0.5,0.0,1.0); +} + void main() { gl_Position = vec4(VertexPosition.xy, 0., 1.); - vs_out.color = vec3(VertexPosition.z, 0., 0.); + vs_out.color = getColor(unit(VertexPosition.z)); } )"; -- cgit v1.2.3