From ce334547f0f0560386ca8b97f354d83da68019a5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 16 Dec 2018 22:09:17 +0100 Subject: Generate fluid display using geometry shaders This should provide much more flexibility. For our purpose it would be useful if the vertex shader was executed after the geometry shader (to apply the projection matrix) but alas this is not the case. Thus the MVP matrix is applied during geometry construction and the vertex shader only provides density extraction. --- src/shader/code/geometry.glsl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/shader/code/geometry.glsl (limited to 'src/shader/code/geometry.glsl') 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(); +} +)"; -- cgit v1.2.3