aboutsummaryrefslogtreecommitdiff
path: root/src/shader
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader')
-rw-r--r--src/shader/code/collide.glsl6
-rw-r--r--src/shader/code/fragment.glsl7
-rw-r--r--src/shader/code/geometry.glsl37
-rw-r--r--src/shader/code/vertex.glsl12
-rw-r--r--src/shader/wrap/graphic_shader.cc10
-rw-r--r--src/shader/wrap/graphic_shader.h1
6 files changed, 66 insertions, 7 deletions
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 90af535..936ca89 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -13,7 +13,7 @@ uniform uint nY;
const uint q = 9;
const float omega = 0.6;
-const float velocityDisplayScalar = 500.;
+const float displayAmplifier = 50.;
float get(uint x, uint y, int i, int j) {
return collideCells[q*nX*y + q*x + (i+1)*3 + j+1];
@@ -24,8 +24,8 @@ 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 + velocityDisplayScalar*v.x;
- fluidCells[3*nX*y + 3*x + 1] = float(y)-nY/2 + velocityDisplayScalar*v.y;
+ 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;
}
diff --git a/src/shader/code/fragment.glsl b/src/shader/code/fragment.glsl
index 37e18bd..a4121b8 100644
--- a/src/shader/code/fragment.glsl
+++ b/src/shader/code/fragment.glsl
@@ -1,5 +1,10 @@
static const std::string FRAGMENT_SHADER_CODE = R"(
+#version 430
+
+in vec3 color;
+out vec4 FragColor;
+
void main() {
- gl_FragColor = gl_Color;
+ FragColor = vec4(color.xyz, 0.0);
}
)";
diff --git a/src/shader/code/geometry.glsl b/src/shader/code/geometry.glsl
new file mode 100644
index 0000000..6701b41
--- /dev/null
+++ b/src/shader/code/geometry.glsl
@@ -0,0 +1,37 @@
+static const std::string GEOMETRY_SHADER_CODE = R"(
+#version 430
+
+layout (points) in;
+layout (triangle_strip, max_vertices=4) out;
+
+uniform mat4 MVP;
+
+in VS_OUT {
+ vec3 color;
+} gs_in[];
+
+out vec3 color;
+
+vec4 project(vec4 v) {
+ return MVP * v;
+}
+
+void emitSquareAt(vec4 position) {
+ const float size = 0.2;
+
+ gl_Position = project(position + vec4(-size, -size, 0.0, 0.0));
+ EmitVertex();
+ gl_Position = project(position + vec4( size, -size, 0.0, 0.0));
+ EmitVertex();
+ gl_Position = project(position + vec4(-size, size, 0.0, 0.0));
+ EmitVertex();
+ gl_Position = project(position + vec4( size, size, 0.0, 0.0));
+ EmitVertex();
+}
+
+void main() {
+ 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 0eccad4..0727708 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -1,8 +1,14 @@
static const std::string VERTEX_SHADER_CODE = R"(
-uniform mat4 MVP;
+#version 430
+
+layout (location=0) in vec3 VertexPosition;
+
+out VS_OUT {
+ vec3 color;
+} vs_out;
void main() {
- gl_Position = MVP * vec4(gl_Vertex.xy, 0.0, 1.0);
- gl_FrontColor = gl_Vertex.z * vec4(1., 0., 0., 0.);
+ gl_Position = vec4(VertexPosition.xy, 0., 1.);
+ vs_out.color = vec3(VertexPosition.z, 0., 0.);
}
)";
diff --git a/src/shader/wrap/graphic_shader.cc b/src/shader/wrap/graphic_shader.cc
index 0ed37ff..c891730 100644
--- a/src/shader/wrap/graphic_shader.cc
+++ b/src/shader/wrap/graphic_shader.cc
@@ -15,6 +15,16 @@ GraphicShader::Guard GraphicShader::use() const {
return Guard(_id);
}
+GraphicShader::GraphicShader(const std::string& vertex,
+ const std::string& geometry,
+ const std::string fragment):
+ _id(glCreateProgram()) {
+ glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
+ glAttachShader(_id, util::compileShader(geometry, GL_GEOMETRY_SHADER));
+ glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER));
+ glLinkProgram(_id);
+}
+
GraphicShader::GraphicShader(const std::string& vertex, const std::string fragment):
_id(glCreateProgram()) {
glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
diff --git a/src/shader/wrap/graphic_shader.h b/src/shader/wrap/graphic_shader.h
index 25a5efb..dcae6db 100644
--- a/src/shader/wrap/graphic_shader.h
+++ b/src/shader/wrap/graphic_shader.h
@@ -20,6 +20,7 @@ public:
Guard use() const;
+ GraphicShader(const std::string& vertex, const std::string& geometry, const std::string fragment);
GraphicShader(const std::string& vertex, const std::string fragment);
~GraphicShader();