blob: 5d286bd1090cc9796a63efac10adfe13c6c1c937 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#extension GL_ARB_gpu_shader5 : enable
#ifdef GL_ARB_gpu_shader5
#define USE_INVOC_EXT
#endif
#define DOUBLE_MANIFOLD
#ifdef DOUBLE_MANIFOLD
# ifdef USE_INVOC_EXT
# define invoc_ct 4
# else
# define vert_ct 12
# endif
#else
# ifdef USE_INVOC_EXT
# define invoc_ct 2
# else
# define vert_ct 6
# endif
#endif
#ifdef USE_INVOC_EXT
layout(triangles, invocations = invoc_ct) in;
layout(triangle_strip, max_vertices = 3) out;
#else
layout(triangles) in;
layout(triangle_strip, max_vertices = vert_ct) out;
#endif
uniform vec3 lightDirection = vec3(0.57, 0.57, -0.57);
in VertexData {
vec3 pos; /* local position */
vec4 frontPosition; /* final ndc position */
vec4 backPosition;
} vData[];
vec4 get_pos(int v, bool backface)
{
return (backface) ? vData[v].backPosition : vData[v].frontPosition;
}
void emit_cap(const bool front)
{
if (front) {
gl_Position = vData[0].frontPosition; EmitVertex();
gl_Position = vData[1].frontPosition; EmitVertex();
gl_Position = vData[2].frontPosition; EmitVertex();
}
else {
gl_Position = vData[0].backPosition; EmitVertex();
gl_Position = vData[2].backPosition; EmitVertex();
gl_Position = vData[1].backPosition; EmitVertex();
}
EndPrimitive();
}
void main()
{
vec3 v10 = vData[0].pos - vData[1].pos;
vec3 v12 = vData[2].pos - vData[1].pos;
vec3 n = cross(v12, v10);
float facing = dot(n, lightDirection);
bool backface = facing > 0.0;
if (!backface) {
#ifdef USE_INVOC_EXT
bool do_front = (gl_InvocationID & 1) == 0;
emit_cap(do_front);
#else
emit_cap(true);
emit_cap(false);
# ifdef DOUBLE_MANIFOLD
emit_cap(true);
emit_cap(false);
# endif
#endif
}
}
|