33
44// #version 420 // Keep it for text editor detection
55
6+ #define ACCURATE_LINES 1
7+ #define ACCURATE_TRIANGLES 2
8+
9+ #if VS_ACCURATE_PRIMS
10+ flat out uint accurate_prims_index;
11+ #if VS_ACCURATE_PRIMS == ACCURATE_TRIANGLES
12+ flat out uint accurate_triangles_interior;
13+ #endif
14+ #endif
15+
616layout (std140, binding = 1 ) uniform cb20
717{
818 vec2 VertexScale;
@@ -14,6 +24,8 @@ layout(std140, binding = 1) uniform cb20
1424 vec2 PointSize;
1525 uint MaxDepth;
1626 uint pad_cb20;
27+ uint BaseVertex;
28+ uint pad_cb20_2;
1729};
1830
1931#ifdef VERTEX_SHADER
@@ -75,6 +87,28 @@ void vs_main()
7587 gl_Position .z = float (z) * exp_min32;
7688 gl_Position .w = 1 .0f;
7789
90+ #if VS_ACCURATE_PRIMS == ACCURATE_LINES
91+ accurate_prims_index = (gl_VertexID - BaseVertex) / 6 ;
92+ VSout.t_float = vec4 (0 .0f);
93+ VSout.t_int = vec4 (0 .0f);
94+ VSout.c = vec4 (0 .0f);
95+ return ; // Don't send line vertex attributes - they are interpolated manually in the fragment shader.
96+ #elif VS_ACCURATE_PRIMS == ACCURATE_TRIANGLES
97+ uint vertex_id = gl_VertexID - BaseVertex;
98+ uint prim_id = vertex_id / 21 ;
99+ accurate_triangles_interior = uint ((vertex_id - 21 * prim_id) < 3 ); // First 3 vertices in each group of 21 is interior.
100+ if (! bool (accurate_triangles_interior))
101+ {
102+ uint edge = (vertex_id - 21 * prim_id - 3 ) / 6 ; // Each group of 6 vertices after first 3 is one edge.
103+ accurate_prims_index = 3 * prim_id + edge;
104+ VSout.t_float = vec4 (0 .0f);
105+ VSout.t_int = vec4 (0 .0f);
106+ VSout.c = vec4 (0 .0f);
107+ return ; // Don't send edge vertex attributes - they are interpolated manually in the fragment shader.
108+ }
109+ // Send the interior vertex attributes for fixed function interpolation.
110+ #endif
111+
78112 texture_coord();
79113
80114 VSout.c = i_c;
0 commit comments