-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_stipple.geom
More file actions
79 lines (67 loc) · 2.06 KB
/
line_stipple.geom
File metadata and controls
79 lines (67 loc) · 2.06 KB
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
#version 330
layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;
// Input Vertex Data
in worldData
{
vec3 position;
vec3 normal;
vec4 color;
}
vertices[];
// Output Fragment Data
out fragData
{
vec3 position;
vec3 normal;
vec4 color;
}
frag;
uniform vec2 viewportSize;
uniform float lineWidth = 1.5;
// Copy clip distances for specified input vertex
void applyClipping(int inVertexID)
{
gl_ClipDistance[0] = gl_in[inVertexID].gl_ClipDistance[0];
gl_ClipDistance[1] = gl_in[inVertexID].gl_ClipDistance[1];
gl_ClipDistance[2] = gl_in[inVertexID].gl_ClipDistance[2];
gl_ClipDistance[3] = gl_in[inVertexID].gl_ClipDistance[3];
gl_ClipDistance[4] = gl_in[inVertexID].gl_ClipDistance[4];
gl_ClipDistance[5] = gl_in[inVertexID].gl_ClipDistance[5];
}
void main()
{
vec4 p1 = gl_in[0].gl_Position;
vec4 p2 = gl_in[1].gl_Position;
vec2 dir = normalize((p2.xy - p1.xy) * viewportSize);
vec2 offset = vec2(-dir.y, dir.x) * lineWidth / viewportSize;
// Emit the four corners of our two triangles
gl_Position = p1 + vec4(offset.xy * p1.w, 0.0, 0.0);
applyClipping(0);
frag.position = vec3(gl_Position);
frag.color = vertices[0].color;
frag.normal = vertices[1].normal;
EmitVertex();
gl_Position = p1 - vec4(offset.xy * p1.w, 0.0, 0.0);
applyClipping(0);
frag.position = vec3(gl_Position);
frag.color = vertices[0].color;
frag.normal = vertices[0].normal;
EmitVertex();
gl_Position = p2 + vec4(offset.xy * p2.w, 0.0, 0.0);
applyClipping(1);
frag.position = vec3(gl_Position);
frag.color = vertices[1].color;
frag.normal = vertices[1].normal;
EmitVertex();
gl_Position = p2 - vec4(offset.xy * p2.w, 0.0, 0.0);
applyClipping(1);
frag.position = vec3(gl_Position);
frag.color = vertices[1].color;
frag.normal = vertices[1].normal;
// To view line-stipple output, remove comment bars (//) from the following two lines
//gl_Position = p1 + vec4(offset.xy * p1.w, 0.0, 0.0);
//applyClipping(0);
EmitVertex();
EndPrimitive();
}