aboutsummaryrefslogtreecommitdiff
path: root/src/shader/code/geometry.glsl
blob: e74d52f4f555ec6d099f680fd278bae9cc92cf15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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.5;

	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();
}
)";