From 3aeb44cd79633827ac83d150fe7440b3761585bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 25 Mar 2019 22:46:47 +0100 Subject: Fix T62260 edges display bug on big geometries when looked up close --- .../draw/modes/shaders/edit_mesh_overlay_geom.glsl | 38 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'source/blender/draw') diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl index 9a0bda3b81d..1afc7bf7b8e 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl @@ -14,13 +14,13 @@ flat out vec4 finalColorOuter_f; out vec4 finalColor_f; out float edgeCoord_f; -void do_vertex(const int i, float coord, vec2 offset) +void do_vertex(const int i, vec4 pos, float coord, vec2 offset) { finalColor_f = (selectOveride[0] == 0) ? finalColor[i] : finalColor[0]; edgeCoord_f = coord; - gl_Position = gl_in[i].gl_Position; + gl_Position = pos; /* Multiply offset by 2 because gl_Position range is [-1..1]. */ - gl_Position.xy += offset * 2.0 * gl_Position.w; + gl_Position.xy += offset * 2.0 * pos.w; #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_set_clip_distance(gl_in[i].gl_ClipDistance); #endif @@ -30,8 +30,28 @@ void do_vertex(const int i, float coord, vec2 offset) void main() { vec2 ss_pos[2]; - ss_pos[0] = gl_in[0].gl_Position.xy / gl_in[0].gl_Position.w; - ss_pos[1] = gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w; + + /* Clip line against near plane to avoid deformed lines. */ + vec4 pos0 = gl_in[0].gl_Position; + vec4 pos1 = gl_in[1].gl_Position; + vec2 pz_ndc = vec2(pos0.z / pos0.w, pos1.z / pos1.w); + bvec2 clipped = lessThan(pz_ndc, vec2(-1.0)); + if (all(clipped)) { + /* Totally clipped. */ + return; + } + + vec4 pos01 = pos0 - pos1; + float ofs = abs((pz_ndc.y + 1.0) / (pz_ndc.x - pz_ndc.y)); + if (clipped.y) { + pos1 += pos01 * ofs; + } + else if (clipped.x) { + pos0 -= pos01 * (1.0 - ofs); + } + + ss_pos[0] = pos0.xy / pos0.w; + ss_pos[1] = pos1.xy / pos1.w; vec2 line = ss_pos[0] - ss_pos[1]; line = abs(line) * viewportSize; @@ -51,10 +71,10 @@ void main() bool horizontal = line.x > line.y; edge_ofs = (horizontal) ? edge_ofs.zyz : edge_ofs.xzz; - 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); + do_vertex(0, pos0, half_size, edge_ofs.xy); + do_vertex(0, pos0, -half_size, -edge_ofs.xy); + do_vertex(1, pos1, half_size, edge_ofs.xy); + do_vertex(1, pos1, -half_size, -edge_ofs.xy); EndPrimitive(); } -- cgit v1.2.3