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

common_subdiv_ibo_lines_comp.glsl « shaders « intern « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3244b7960d878de1ad630246a4c0ceee0d4d7f2f (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
83
84
85
86

/* To be compiled with common_subdiv_lib.glsl */

layout(std430, binding = 1) readonly buffer inputEdgeOrigIndex
{
  int input_origindex[];
};

layout(std430, binding = 2) readonly restrict buffer extraCoarseFaceData
{
  uint extra_coarse_face_data[];
};

layout(std430, binding = 3) writeonly buffer outputLinesIndices
{
  uint output_lines[];
};

layout(std430, binding = 4) readonly buffer LinesLooseFlags
{
  uint lines_loose_flags[];
};

#ifndef LINES_LOOSE

bool is_face_hidden(uint coarse_quad_index)
{
  return (extra_coarse_face_data[coarse_quad_index] & coarse_face_hidden_mask) != 0;
}

void emit_line(uint line_offset, uint quad_index, uint start_loop_index, uint corner_index)
{
  uint vertex_index = start_loop_index + corner_index;

  uint coarse_quad_index = coarse_polygon_index_from_subdiv_quad_index(quad_index,
                                                                       coarse_poly_count);

  if (is_face_hidden(coarse_quad_index) ||
      (input_origindex[vertex_index] == ORIGINDEX_NONE && optimal_display)) {
    output_lines[line_offset + 0] = 0xffffffff;
    output_lines[line_offset + 1] = 0xffffffff;
  }
  else {
    /* Mod 4 so we loop back at the first vertex on the last loop index (3). */
    uint next_vertex_index = start_loop_index + (corner_index + 1) % 4;

    output_lines[line_offset + 0] = vertex_index;
    output_lines[line_offset + 1] = next_vertex_index;
  }
}
#endif

void main()
{
  uint index = get_global_invocation_index();
  if (index >= total_dispatch_size) {
    return;
  }

#ifdef LINES_LOOSE
  /* In the loose lines case, we execute for each line, with two vertices per line. */
  uint line_offset = edge_loose_offset + index * 2;
  uint loop_index = num_subdiv_loops + index * 2;

  if (lines_loose_flags[index] != 0) {
    /* Line is hidden. */
    output_lines[line_offset] = 0xffffffff;
    output_lines[line_offset + 1] = 0xffffffff;
  }
  else {
    output_lines[line_offset] = loop_index;
    output_lines[line_offset + 1] = loop_index + 1;
  }

#else
  /* We execute for each quad, so the start index of the loop is quad_index * 4. */
  uint start_loop_index = index * 4;
  /* We execute for each quad, so the start index of the line is quad_index * 8 (with 2 vertices
   * per line). */
  uint start_line_index = index * 8;

  for (int i = 0; i < 4; i++) {
    emit_line(start_line_index + i * 2, index, start_loop_index, i);
  }
#endif
}