[Bf-blender-cvs] [6f9cfb037a8] master: Sculpt: Fix T102991: Multires fast navigate not implemented

Joseph Eagar noreply at git.blender.org
Tue Dec 13 22:52:52 CET 2022


Commit: 6f9cfb037a8e5dbd8707877d0a9539ae8d358656
Author: Joseph Eagar
Date:   Tue Dec 13 12:24:24 2022 -0800
Branches: master
https://developer.blender.org/rB6f9cfb037a8e5dbd8707877d0a9539ae8d358656

Sculpt: Fix T102991: Multires fast navigate not implemented

PBVH draw code now builds coarse triangle index buffers
for multires. Note that the coarse grids can be at any
multires depth but is currently hardcoded to 1.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/draw/DRW_pbvh.h
M	source/blender/draw/intern/draw_manager_data.cc
M	source/blender/draw/intern/draw_pbvh.cc
M	source/blender/gpu/intern/gpu_shader_builder_stubs.cc

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 139b6ff6bbe..8f66d552387 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -414,7 +414,8 @@ void BKE_pbvh_sync_visibility_from_verts(PBVH *pbvh, struct Mesh *me);
 int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
                               const int *grid_indices,
                               int totgrid,
-                              int gridsize);
+                              int gridsize,
+                              int display_gridsize);
 
 /**
  * Multi-res level, only valid for type == #PBVH_GRIDS.
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 98e21c685a2..35c2c660fd2 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -383,7 +383,8 @@ static void update_vb(PBVH *pbvh, PBVHNode *node, BBC *prim_bbc, int offset, int
 int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
                               const int *grid_indices,
                               int totgrid,
-                              int gridsize)
+                              int gridsize,
+                              int display_gridsize)
 {
   const int gridarea = (gridsize - 1) * (gridsize - 1);
   int totquad = 0;
@@ -391,13 +392,18 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
   /* grid hidden layer is present, so have to check each grid for
    * visibility */
 
+  int depth1 = (int)(log2((double)gridsize - 1.0) + DBL_EPSILON);
+  int depth2 = (int)(log2((double)display_gridsize - 1.0) + DBL_EPSILON);
+
+  int skip = depth2 < depth1 ? 1 << (depth1 - depth2 - 1) : 1;
+
   for (int i = 0; i < totgrid; i++) {
     const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
 
     if (gh) {
       /* grid hidden are present, have to check each element */
-      for (int y = 0; y < gridsize - 1; y++) {
-        for (int x = 0; x < gridsize - 1; x++) {
+      for (int y = 0; y < gridsize - skip; y += skip) {
+        for (int x = 0; x < gridsize - skip; x += skip) {
           if (!paint_is_grid_face_hidden(gh, gridsize, x, y)) {
             totquad++;
           }
@@ -414,8 +420,11 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
 
 static void build_grid_leaf_node(PBVH *pbvh, PBVHNode *node)
 {
-  int totquads = BKE_pbvh_count_grid_quads(
-      pbvh->grid_hidden, node->prim_indices, node->totprim, pbvh->gridkey.grid_size);
+  int totquads = BKE_pbvh_count_grid_quads(pbvh->grid_hidden,
+                                           node->prim_indices,
+                                           node->totprim,
+                                           pbvh->gridkey.grid_size,
+                                           pbvh->gridkey.grid_size);
   BKE_pbvh_node_fully_hidden_set(node, (totquads == 0));
   BKE_pbvh_node_mark_rebuild_draw(node);
 }
diff --git a/source/blender/draw/DRW_pbvh.h b/source/blender/draw/DRW_pbvh.h
index ffd4b92d87b..6f9daac0a35 100644
--- a/source/blender/draw/DRW_pbvh.h
+++ b/source/blender/draw/DRW_pbvh.h
@@ -86,12 +86,14 @@ struct GPUBatch *DRW_pbvh_tris_get(PBVHBatches *batches,
                                    struct PBVHAttrReq *attrs,
                                    int attrs_num,
                                    PBVH_GPU_Args *args,
-                                   int *r_prim_count);
+                                   int *r_prim_count,
+                                   bool do_coarse_grids);
 struct GPUBatch *DRW_pbvh_lines_get(struct PBVHBatches *batches,
                                     struct PBVHAttrReq *attrs,
                                     int attrs_num,
                                     PBVH_GPU_Args *args,
-                                    int *r_prim_count);
+                                    int *r_prim_count,
+                                    bool do_coarse_grids);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index beeff6f35c2..d4ffd3f8691 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -1220,10 +1220,12 @@ static void sculpt_draw_cb(DRWSculptCallbackData *scd,
   GPUBatch *geom;
 
   if (!scd->use_wire) {
-    geom = DRW_pbvh_tris_get(batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount);
+    geom = DRW_pbvh_tris_get(
+        batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount, scd->fast_mode);
   }
   else {
-    geom = DRW_pbvh_lines_get(batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount);
+    geom = DRW_pbvh_lines_get(
+        batches, scd->attrs, scd->attrs_num, pbvh_draw_args, &primcount, scd->fast_mode);
   }
 
   short index = 0;
diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc
index d56a86ab44c..0bdfbf11cb8 100644
--- a/source/blender/draw/intern/draw_pbvh.cc
+++ b/source/blender/draw/intern/draw_pbvh.cc
@@ -115,6 +115,8 @@ struct PBVHBatch {
   string key;
   GPUBatch *tris = nullptr, *lines = nullptr;
   int tris_count = 0, lines_count = 0;
+  bool is_coarse =
+      false; /* Coarse multires, will use full-sized VBOs only index buffer changes. */
 
   void sort_vbos(Vector<PBVHVbo> &master_vbos)
   {
@@ -138,6 +140,10 @@ struct PBVHBatch {
   {
     key = "";
 
+    if (is_coarse) {
+      key += "c:";
+    }
+
     sort_vbos(master_vbos);
 
     for (int vbo_i : vbos) {
@@ -173,6 +179,12 @@ struct PBVHBatches {
 
   int material_index = 0;
 
+  /* Stuff for displaying coarse multires grids. */
+  GPUIndexBuf *tri_index_coarse = nullptr;
+  GPUIndexBuf *lines_index_coarse = nullptr;
+  int coarse_level = 0; /* Coarse multires depth. */
+  int tris_count_coarse = 0, lines_count_coarse = 0;
+
   int count_faces(PBVH_GPU_Args *args)
   {
     int count = 0;
@@ -194,6 +206,7 @@ struct PBVHBatches {
         count = BKE_pbvh_count_grid_quads((BLI_bitmap **)args->grid_hidden,
                                           args->grid_indices,
                                           args->totprim,
+                                          args->ccg_key.grid_size,
                                           args->ccg_key.grid_size);
 
         break;
@@ -233,9 +246,11 @@ struct PBVHBatches {
 
     GPU_INDEXBUF_DISCARD_SAFE(tri_index);
     GPU_INDEXBUF_DISCARD_SAFE(lines_index);
+    GPU_INDEXBUF_DISCARD_SAFE(tri_index_coarse);
+    GPU_INDEXBUF_DISCARD_SAFE(lines_index_coarse);
   }
 
-  string build_key(PBVHAttrReq *attrs, int attrs_num)
+  string build_key(PBVHAttrReq *attrs, int attrs_num, bool do_coarse_grids)
   {
     string key;
     PBVHBatch batch;
@@ -255,6 +270,7 @@ struct PBVHBatches {
       batch.vbos.append(i);
     }
 
+    batch.is_coarse = do_coarse_grids;
     batch.build_key(vbos);
     return batch.key;
   }
@@ -292,18 +308,21 @@ struct PBVHBatches {
     return nullptr;
   }
 
-  bool has_batch(PBVHAttrReq *attrs, int attrs_num)
+  bool has_batch(PBVHAttrReq *attrs, int attrs_num, bool do_coarse_grids)
   {
-    return batches.contains(build_key(attrs, attrs_num));
+    return batches.contains(build_key(attrs, attrs_num, do_coarse_grids));
   }
 
-  PBVHBatch &ensure_batch(PBVHAttrReq *attrs, int attrs_num, PBVH_GPU_Args *args)
+  PBVHBatch &ensure_batch(PBVHAttrReq *attrs,
+                          int attrs_num,
+                          PBVH_GPU_Args *args,
+                          bool do_coarse_grids)
   {
-    if (!has_batch(attrs, attrs_num)) {
-      create_batch(attrs, attrs_num, args);
+    if (!has_batch(attrs, attrs_num, do_coarse_grids)) {
+      create_batch(attrs, attrs_num, args, do_coarse_grids);
     }
 
-    return batches.lookup(build_key(attrs, attrs_num));
+    return batches.lookup(build_key(attrs, attrs_num, do_coarse_grids));
   }
 
   void fill_vbo_normal_faces(
@@ -504,9 +523,12 @@ struct PBVHBatches {
               for (int x = 0; x < gridsize; x++) {
                 CCGElem *elems[4] = {
                     CCG_grid_elem(&args->ccg_key, grid, x, y),
-                    CCG_grid_elem(&args->ccg_key, grid, x + 1, y),
-                    CCG_grid_elem(&args->ccg_key, grid, x + 1, y + 1),
-                    CCG_grid_elem(&args->ccg_key, grid, x, y + 1),
+                    CCG_grid_elem(&args->ccg_key, grid, min_ii(x + 1, gridsize - 1), y),
+                    CCG_grid_elem(&args->ccg_key,
+                                  grid,
+                                  min_ii(x + 1, gridsize - 1),
+                                  min_ii(y + 1, gridsize - 1)),
+                    CCG_grid_elem(&args->ccg_key, grid, x, min_ii(y + 1, gridsize - 1)),
                 };
 
                 func(x, y, grid_index, elems, 0);
@@ -964,8 +986,10 @@ struct PBVHBatches {
 
         GPU_INDEXBUF_DISCARD_SAFE(tri_index);
         GPU_INDEXBUF_DISCARD_SAFE(lines_index);
+        GPU_INDEXBUF_DISCARD_SAFE(tri_index_coarse);
+        GPU_INDEXBUF_DISCARD_SAFE(lines_index_coarse);
 
-        tri_index = lines_index = nullptr;
+        tri_index = lines_index = tri_index_coarse = lines_index_coarse = nullptr;
         faces_count = tris_count = count;
       }
     }
@@ -1061,7 +1085,7 @@ struct PBVHBatches {
     lines_index = GPU_indexbuf_build(&elb_lines);
   }
 
-  void create_index_grids(PBVH_GPU_Args *args)
+  void create_index_grids(PBVH_GPU_Args *args, bool do_coarse)
   {
     int *mat_index = static_cast<int *>(
         CustomData_get_layer_named(args->pdata, CD_PROP_INT32, "material_index"));
@@ -1073,15 +1097,24 @@ struct PBVHBatches {
 
     needs_tri_index = true;
     int gridsize = args->ccg_key.grid_size;
+    int display_gridsize = gridsize;
     int totgrid = args->totprim;
+    int skip = 1;
+
+    const int display_level = do_coarse ? coarse_level : args->ccg_key.level;
+
+    if (display_level < args->ccg_key.level) {
+      display_gridsize = (1 << display_level) + 1;
+      skip = 1 << (args->ccg_key.level - display_level - 1);
+    }
 
     for (int i : IndexRange(args->totprim)) {
       int grid_index = args->grid_indices[i];
       bool smooth = args->grid_flag_mats[grid_index].flag & ME_SMOOTH;
  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list