diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-09-27 12:09:50 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-09-27 15:29:40 +0300 |
commit | d3a98b2c3b44244bff3b0386f33a277286b26f59 (patch) | |
tree | f3237ffe4d9f28a1800ada53f8ee9e5ce700df2a /source | |
parent | 0901a72b6b36b0bc0d2b0783a949e66dcb17a91c (diff) |
Fix part of T70295: sculpt drawing not clipping PBVH nodes outside of viewport
As before in 2.7, this only works for optimized drawing in workbench mode.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 4bed8cf6a40..302d726f74e 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -888,6 +888,29 @@ static void sculpt_debug_cb(void *user_data, } #endif +static void drw_sculpt_get_frustum_planes(Object *ob, float planes[4][4]) +{ + /* TODO: take into account partial redraw for clipping planes. */ + float frustum_planes[6][4]; + DRW_view_frustum_planes_get(DRW_view_default_get(), frustum_planes); + + /* PBVH only needs X/Y clipping planes, no Z depth. + * TODO: support Z depth clipping in PBVH. */ + copy_v4_v4(planes[0], frustum_planes[0]); + copy_v4_v4(planes[1], frustum_planes[1]); + copy_v4_v4(planes[2], frustum_planes[3]); + copy_v4_v4(planes[3], frustum_planes[5]); + + /* Transform clipping planes to object space. Transforming a plane with a + * 4x4 matrix is done by multiplying with the tranpose inverse. The inverse + * cancels out here since we transform by inverse(obmat). */ + float tmat[4][4]; + transpose_m4_m4(tmat, ob->obmat); + for (int i = 0; i < 4; i++) { + mul_m4_v4(tmat, planes[i]); + } +} + static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd, bool use_vcol) { /* PBVH should always exist for non-empty meshes, created by depsgrah eval. */ @@ -896,7 +919,9 @@ static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd, bool use_vcol) return; } - float(*planes)[4] = NULL; /* TODO proper culling. */ + float planes[4][4]; + drw_sculpt_get_frustum_planes(scd->ob, planes); + scd->fast_mode = false; const DRWContextState *drwctx = DRW_context_state_get(); |