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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-03-26 00:46:47 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-03-26 17:11:31 +0300
commit3aeb44cd79633827ac83d150fe7440b3761585bd (patch)
treef84ce038079b2cf8c5d2cac213cfcae88c4bc219 /source/blender/draw
parent33a759a39c9493dd2c89068107e697e0d84a81b2 (diff)
Fix T62260 edges display bug on big geometries when looked up close
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl38
1 files changed, 29 insertions, 9 deletions
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();
}