diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-01-18 12:22:11 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-01-18 12:23:05 +0300 |
commit | d5b4d71ee7b8e5d23f1317917b94a5666ebda5e1 (patch) | |
tree | 58a0efcf80bd143dd7e4d4a7046a8a5c4e8dd9a6 | |
parent | a7b8538f4c8d77107f8c6be01cd9fcdb80acacb6 (diff) |
DRW: Increase frustum culling precision
Use normal_quad_v3 instead of normal_tri_v3 and compute the mean of all
corner distance during frustum plane extraction.
Fix T58243 Flickering of viewport when rotating and zooming
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 1f1ccc7a66e..5ac102084cd 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -532,21 +532,26 @@ static void draw_clipping_setup_from_view(void) /* Compute clip planes using the world space frustum corners. */ for (int p = 0; p < 6; p++) { - int q, r; + int q, r, s; switch (p) { - case 0: q = 1; r = 2; break; /* -X */ - case 1: q = 0; r = 5; break; /* -Y */ - case 2: q = 1; r = 5; break; /* +Z (far) */ - case 3: q = 2; r = 6; break; /* +Y */ - case 4: q = 0; r = 3; break; /* -Z (near) */ - default: q = 4; r = 7; break; /* +X */ + case 0: q = 1; r = 2; s = 3; break; /* -X */ + case 1: q = 0; r = 4; s = 5; break; /* -Y */ + case 2: q = 1; r = 5; s = 6; break; /* +Z (far) */ + case 3: q = 2; r = 6; s = 7; break; /* +Y */ + case 4: q = 0; r = 3; s = 7; break; /* -Z (near) */ + default: q = 4; r = 7; s = 6; break; /* +X */ } if (DST.frontface == GL_CW) { SWAP(int, q, r); } - normal_tri_v3(DST.clipping.frustum_planes[p], bbox.vec[p], bbox.vec[q], bbox.vec[r]); - DST.clipping.frustum_planes[p][3] = -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[p]); + normal_quad_v3(DST.clipping.frustum_planes[p], bbox.vec[p], bbox.vec[q], bbox.vec[r], bbox.vec[s]); + /* Increase precision and use the mean of all 4 corners. */ + DST.clipping.frustum_planes[p][3] = -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[p]); + DST.clipping.frustum_planes[p][3] += -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[q]); + DST.clipping.frustum_planes[p][3] += -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[r]); + DST.clipping.frustum_planes[p][3] += -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[s]); + DST.clipping.frustum_planes[p][3] *= 0.25f; } /* Extract Bounding Sphere */ |