Edit Mesh: Rework new implementation and use geometry shader to draw lines
This make it (theoriticaly) compatible with all supported hardware with consistent results. Also we now draw the lines with analytic anti-aliasing instead of relying on MSAA (which offers less benefits in our case). The remaining aliasing comes from edges cut in half by the mesh which is not rendered with MSAA. Hopefully this is not too much distracting and only happen if the face is almost parallel to the view.
This commit is contained in:
@@ -4,33 +4,23 @@ layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
uniform vec2 viewportSize;
|
||||
uniform vec2 viewportSizeInv;
|
||||
uniform float edgeScale;
|
||||
|
||||
in VertexData {
|
||||
vec4 finalColor;
|
||||
#if defined(EDGE) && !defined(FLAT)
|
||||
int selectOveride;
|
||||
#endif
|
||||
} v[];
|
||||
in vec4 finalColor[2];
|
||||
in vec4 finalColorOuter[2];
|
||||
in int selectOveride[2];
|
||||
|
||||
#ifdef FLAT
|
||||
# define interp_col flat
|
||||
#else
|
||||
# define interp_col
|
||||
#endif
|
||||
flat out vec4 finalColorOuter_f;
|
||||
out vec4 finalColor_f;
|
||||
out float edgeCoord_f;
|
||||
|
||||
interp_col out vec4 finalColor;
|
||||
#if defined(EDGE) && !defined(FLAT)
|
||||
flat out int selectOveride;
|
||||
#endif
|
||||
|
||||
void do_vertex(const int i, vec2 offset)
|
||||
void do_vertex(const int i, float coord, vec2 offset)
|
||||
{
|
||||
finalColor = v[i].finalColor;
|
||||
#if defined(EDGE) && !defined(FLAT)
|
||||
selectOveride = v[0].selectOveride;
|
||||
#endif
|
||||
finalColor_f = (selectOveride[0] == 0) ? finalColor[i] : finalColor[0];
|
||||
edgeCoord_f = coord;
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
gl_Position.xy += offset * gl_Position.w;
|
||||
/* Multiply offset by 2 because gl_Position range is [-1..1]. */
|
||||
gl_Position.xy += offset * 2.0 * gl_Position.w;
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
@@ -41,25 +31,24 @@ void main()
|
||||
ss_pos[1] = gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w;
|
||||
|
||||
vec2 line = ss_pos[0] - ss_pos[1];
|
||||
line *= viewportSize;
|
||||
line = abs(line) * viewportSize;
|
||||
|
||||
vec3 edge_ofs = sizeEdge * 2.0 * viewportSizeInv.xyy * vec3(1.0, 1.0, 0.0);
|
||||
finalColorOuter_f = finalColorOuter[0];
|
||||
float half_size = sizeEdge * edgeScale;
|
||||
/* Enlarge edge for flag display. */
|
||||
half_size += (finalColorOuter_f.a > 0.0) ? max(sizeEdge * edgeScale, 1.0) : 0.0;
|
||||
/* Add 1 px for AA */
|
||||
half_size += 0.5;
|
||||
|
||||
#ifdef EDGE_DECORATION
|
||||
edge_ofs *= 3.0;
|
||||
vec3 edge_ofs = half_size * viewportSizeInv.xyy * vec3(1.0, 1.0, 0.0);
|
||||
|
||||
if (finalColor.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool horizontal = abs(line.x) > abs(line.y);
|
||||
bool horizontal = line.x > line.y;
|
||||
edge_ofs = (horizontal) ? edge_ofs.zyz : edge_ofs.xzz;
|
||||
|
||||
do_vertex(0, edge_ofs.xy);
|
||||
do_vertex(0, -edge_ofs.xy);
|
||||
do_vertex(1, edge_ofs.xy);
|
||||
do_vertex(1, -edge_ofs.xy);
|
||||
do_vertex(0, half_size, edge_ofs.xy);
|
||||
do_vertex(0, -half_size, -edge_ofs.xy);
|
||||
do_vertex(1, half_size, edge_ofs.xy);
|
||||
do_vertex(1, -half_size, -edge_ofs.xy);
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user