blob: ed281141e16a3a99884c7bc595d987d9e49d1a84 (
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
|
// Draw "fancy" wireframe, displaying front-facing, back-facing and
// silhouette lines differently.
// Mike Erwin, April 2015
uniform bool drawFront = true;
uniform bool drawBack = true;
uniform bool drawSilhouette = true;
uniform vec4 frontColor;
uniform vec4 backColor;
uniform vec4 silhouetteColor;
uniform vec3 eye; // direction we are looking
uniform mat4 ModelViewProjectionMatrix;
#if __VERSION__ == 120
attribute vec3 pos;
// normals of faces this edge joins (object coords)
attribute vec3 N1;
attribute vec3 N2;
flat varying vec4 finalColor;
#else
in vec3 pos;
// normals of faces this edge joins (object coords)
in vec3 N1;
in vec3 N2;
flat out vec4 finalColor;
#endif
// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
// to discard an entire line, set both endpoints to nowhere
// and it won't produce any fragments
const vec4 nowhere = vec4(vec3(0.0), 1.0);
void main()
{
bool face_1_front = dot(N1, eye) > 0.0;
bool face_2_front = dot(N2, eye) > 0.0;
vec4 position = ModelViewProjectionMatrix * vec4(pos, 1.0);
if (face_1_front && face_2_front) {
// front-facing edge
gl_Position = drawFront ? position : nowhere;
finalColor = frontColor;
}
else if (face_1_front || face_2_front) {
// exactly one face is front-facing, silhouette edge
gl_Position = drawSilhouette ? position : nowhere;
finalColor = silhouetteColor;
}
else {
// back-facing edge
gl_Position = drawBack ? position : nowhere;
finalColor = backColor;
}
}
|