[Bf-blender-cvs] [d3a98b2c3b4] master: Fix part of T70295: sculpt drawing not clipping PBVH nodes outside of viewport

Brecht Van Lommel noreply at git.blender.org
Fri Sep 27 14:32:37 CEST 2019


Commit: d3a98b2c3b44244bff3b0386f33a277286b26f59
Author: Brecht Van Lommel
Date:   Fri Sep 27 11:09:50 2019 +0200
Branches: master
https://developer.blender.org/rBd3a98b2c3b44244bff3b0386f33a277286b26f59

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.

===================================================================

M	source/blender/draw/intern/draw_manager_data.c

===================================================================

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();



More information about the Bf-blender-cvs mailing list