Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_shader_edges_front_back_ortho_vert.glsl « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a71dfba575b1eed118ce49719ae3a6e253ae1308 (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

// 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;

in vec3 pos;

// normals of faces this edge joins (object coords)
in vec3 N1;
in vec3 N2;

flat out vec4 finalColor;

// 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;
  }
}