[Bf-blender-cvs] [3aeb44cd796] master: Fix T62260 edges display bug on big geometries when looked up close
Clément Foucault
noreply at git.blender.org
Tue Mar 26 15:11:34 CET 2019
Commit: 3aeb44cd79633827ac83d150fe7440b3761585bd
Author: Clément Foucault
Date: Mon Mar 25 22:46:47 2019 +0100
Branches: master
https://developer.blender.org/rB3aeb44cd79633827ac83d150fe7440b3761585bd
Fix T62260 edges display bug on big geometries when looked up close
===================================================================
M source/blender/draw/modes/shaders/edit_mesh_overlay_geom.glsl
===================================================================
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();
}
More information about the Bf-blender-cvs
mailing list