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.
This commit is contained in:
Joseph Eagar 2022-08-15 17:01:17 -07:00
parent c5feb4e6fe
commit 7f3eb055dd
6 changed files with 45 additions and 16 deletions

View File

@ -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
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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])

View File

@ -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);
}
}

View File

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