[Bf-blender-cvs] [7f3eb055dd0] master: Sculpt: Improve sculpt debug draw

Joseph Eagar noreply at git.blender.org
Tue Aug 16 02:04:01 CEST 2022


Commit: 7f3eb055dd0c708cb775332115be37dec0075e43
Author: Joseph Eagar
Date:   Mon Aug 15 17:01:17 2022 -0700
Branches: master
https://developer.blender.org/rB7f3eb055dd0c708cb775332115be37dec0075e43

Sculpt: Improve sculpt debug draw

* Fixed crash in debug draw code.  Apparently this is
  only used by PBVH draw?
* Debug draw code can now be forcibly enabled in release
  mode (i.e. RelWithDebugInfo) by uncommenting a commented
  out #define.
* Fixed colors in debug draw mode.
* PBVH node boxes in debug mode now flash a different color
  when they are updated.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/draw/intern/draw_debug.cc
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/intern/shaders/draw_debug_draw_display_vert.glsl

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 2be3f323d07..8c9488b0b46 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -350,10 +350,13 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
                       void *user_data,
                       bool full_render);
 
-void BKE_pbvh_draw_debug_cb(
-    PBVH *pbvh,
-    void (*draw_fn)(void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag),
-    void *user_data);
+void BKE_pbvh_draw_debug_cb(PBVH *pbvh,
+                            void (*draw_fn)(PBVHNode *node,
+                                            void *user_data,
+                                            const float bmin[3],
+                                            const float bmax[3],
+                                            PBVHNodeFlags flag),
+                            void *user_data);
 
 /* PBVH Access */
 
@@ -711,6 +714,7 @@ void BKE_pbvh_vertex_color_get(const PBVH *pbvh, PBVHVertRef vertex, float r_col
 
 void BKE_pbvh_ensure_node_loops(PBVH *pbvh);
 bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh);
+int BKE_pbvh_debug_draw_gen_get(PBVHNode *node);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 4e6418942be..d7fa2ca8e32 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1330,6 +1330,8 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
   }
 
   if (node->flag & PBVH_UpdateDrawBuffers) {
+    node->debug_draw_gen++;
+
     const int update_flags = pbvh_get_buffers_update_flags(pbvh);
     switch (pbvh->header.type) {
       case PBVH_GRIDS:
@@ -2899,13 +2901,13 @@ void BKE_pbvh_draw_cb(PBVH *pbvh,
 
 void BKE_pbvh_draw_debug_cb(
     PBVH *pbvh,
-    void (*draw_fn)(void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag),
+    void (*draw_fn)(PBVHNode *node, void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag),
     void *user_data)
 {
   for (int a = 0; a < pbvh->totnode; a++) {
     PBVHNode *node = &pbvh->nodes[a];
 
-    draw_fn(user_data, node->vb.bmin, node->vb.bmax, node->flag);
+    draw_fn(node, user_data, node->vb.bmin, node->vb.bmax, node->flag);
   }
 }
 
@@ -3330,3 +3332,8 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh)
 
   MEM_SAFE_FREE(visit);
 }
+
+int BKE_pbvh_debug_draw_gen_get(PBVHNode *node)
+{
+  return node->debug_draw_gen;
+}
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 5babfd3acbe..3d67ab9ba6b 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -123,6 +123,11 @@ struct PBVHNode {
   /* Used to store the brush color during a stroke and composite it over the original color */
   PBVHColorBufferNode color_buffer;
   PBVHPixelsNode pixels;
+
+  /* Used to flash colors of updated node bounding boxes in
+   * debug draw mode (when G.debug_value / bpy.app.debug_value is 889).
+   */
+  int debug_draw_gen;
 };
 
 typedef enum { PBVH_DYNTOPO_SMOOTH_SHADING = 1 } PBVHFlags;
diff --git a/source/blender/draw/intern/draw_debug.cc b/source/blender/draw/intern/draw_debug.cc
index aaf18014143..b9d10302c1e 100644
--- a/source/blender/draw/intern/draw_debug.cc
+++ b/source/blender/draw/intern/draw_debug.cc
@@ -21,6 +21,13 @@
 
 #include <iomanip>
 
+#ifdef DEBUG
+#  define DRAW_DEBUG
+#else
+/* Uncomment to forcibly enable debug draw in release mode. */
+//#define DRAW_DEBUG
+#endif
+
 namespace blender::draw {
 
 /* -------------------------------------------------------------------- */
@@ -595,7 +602,7 @@ blender::draw::DebugDraw *DRW_debug_get()
 
 void drw_debug_draw()
 {
-#ifdef DEBUG
+#ifdef DRAW_DEBUG
   if (!GPU_shader_storage_buffer_objects_support() || DST.debug == nullptr) {
     return;
   }
@@ -611,7 +618,7 @@ void drw_debug_init()
 {
   /* Module should not be used in release builds. */
   /* TODO(@fclem): Hide the functions declarations without using `ifdefs` everywhere. */
-#ifdef DEBUG
+#ifdef DRAW_DEBUG
   if (!GPU_shader_storage_buffer_objects_support()) {
     return;
   }
@@ -659,10 +666,12 @@ void DRW_debug_modelmat_reset()
 
 void DRW_debug_modelmat(const float modelmat[4][4])
 {
+#ifdef DRAW_DEBUG
   if (!GPU_shader_storage_buffer_objects_support()) {
     return;
   }
   reinterpret_cast<blender::draw::DebugDraw *>(DST.debug)->modelmat_set(modelmat);
+#endif
 }
 
 void DRW_debug_line_v3v3(const float v1[3], const float v2[3], const float color[4])
@@ -704,10 +713,12 @@ void DRW_debug_m4_as_bbox(const float m[4][4], bool invert, const float color[4]
 
 void DRW_debug_bbox(const BoundBox *bbox, const float color[4])
 {
+#ifdef DRAW_DEBUG
   if (!GPU_shader_storage_buffer_objects_support()) {
     return;
   }
   reinterpret_cast<blender::draw::DebugDraw *>(DST.debug)->draw_bbox(*bbox, color);
+#endif
 }
 
 void DRW_debug_sphere(const float center[3], float radius, const float color[4])
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 1a5d91444fe..abccbd66e80 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1188,16 +1188,15 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd, GPU_PBVH_Buffers *buffers
       DRW_shgroup_uniform_vec3(
           shgrp, "materialDiffuseColor", SCULPT_DEBUG_COLOR(scd->debug_node_nr++), 1);
     }
+
     /* DRW_shgroup_call_no_cull reuses matrices calculations for all the drawcalls of this
      * object. */
     DRW_shgroup_call_no_cull(shgrp, geom, scd->ob);
   }
 }
 
-static void sculpt_debug_cb(void *user_data,
-                            const float bmin[3],
-                            const float bmax[3],
-                            PBVHNodeFlags flag)
+static void sculpt_debug_cb(
+    PBVHNode *node, void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag)
 {
   int *debug_node_nr = (int *)user_data;
   BoundBox bb;
@@ -1212,7 +1211,10 @@ static void sculpt_debug_cb(void *user_data,
   }
 #else /* Color coded leaf bounds. */
   if (flag & PBVH_Leaf) {
-    DRW_debug_bbox(&bb, SCULPT_DEBUG_COLOR((*debug_node_nr)++));
+    int color = (*debug_node_nr)++;
+    color += BKE_pbvh_debug_draw_gen_get(node);
+ 
+    DRW_debug_bbox(&bb, SCULPT_DEBUG_COLOR(color));
   }
 #endif
 }
@@ -1305,8 +1307,8 @@ static void drw_sculpt_generate_calls(DRWSculptCallbackData *scd)
     DRW_debug_modelmat(scd->ob->obmat);
     BKE_pbvh_draw_debug_cb(
         pbvh,
-        (void (*)(
-            void *d, const float min[3], const float max[3], PBVHNodeFlags f))sculpt_debug_cb,
+        (void (*)(PBVHNode * n, void *d, const float min[3], const float max[3], PBVHNodeFlags f))
+            sculpt_debug_cb,
         &debug_node_nr);
   }
 }
diff --git a/source/blender/draw/intern/shaders/draw_debug_draw_display_vert.glsl b/source/blender/draw/intern/shaders/draw_debug_draw_display_vert.glsl
index 92c546aa203..ab76df819d5 100644
--- a/source/blender/draw/intern/shaders/draw_debug_draw_display_vert.glsl
+++ b/source/blender/draw/intern/shaders/draw_debug_draw_display_vert.glsl
@@ -8,7 +8,7 @@ void main()
   /* Skip the first vertex containing header data. */
   DRWDebugVert vert = drw_debug_verts_buf[gl_VertexID + 1];
   vec3 pos = uintBitsToFloat(uvec3(vert.pos0, vert.pos1, vert.pos2));
-  vec4 col = vec4((uvec4(vert.color) >> uvec4(0, 8, 16, 24)) & 0xFFu);
+  vec4 col = vec4((uvec4(vert.color) >> uvec4(0, 8, 16, 24)) & 0xFFu) / 255.0;
 
   interp.color = col;
   gl_Position = persmat * vec4(pos, 1.0);



More information about the Bf-blender-cvs mailing list