[Bf-blender-cvs] [08e19c6bc0e] temp_bmesh_multires: Added debug option in dyntopo to draw sculpt colors as solid cells instead of interpolating (it's next to "draw smooth" in the dyntopo settings panel).

Joseph Eagar noreply at git.blender.org
Fri Nov 6 12:19:10 CET 2020


Commit: 08e19c6bc0e923dc497b1c92ddf7ae89c8429303
Author: Joseph Eagar
Date:   Fri Nov 6 03:17:45 2020 -0800
Branches: temp_bmesh_multires
https://developer.blender.org/rB08e19c6bc0e923dc497b1c92ddf7ae89c8429303

Added debug option in dyntopo to draw sculpt colors as solid cells
instead of interpolating (it's next to "draw smooth" in the dyntopo
settings panel).

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 8c0103d10e6..09ba7fe3940 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -786,6 +786,7 @@ class VIEW3D_PT_sculpt_dyntopo(Panel, View3DPaintPanel):
             col.operator("sculpt.detail_flood_fill")
 
         col.prop(sculpt, "use_smooth_shading")
+        col.prop(sculpt, "use_flat_vcol_shading")
 
 
 class VIEW3D_PT_sculpt_voxel_remesh(Panel, View3DPaintPanel):
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 23573d00d9d..f1baa7db603 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -634,6 +634,7 @@ PBVHColorBufferNode *BKE_pbvh_node_color_buffer_get(PBVHNode *node);
 void BKE_pbvh_node_color_buffer_free(PBVH *pbvh);
 
 int BKE_pbvh_get_node_index(PBVH *pbvh, PBVHNode *node);
+void BKE_pbvh_set_flat_vcol_shading(PBVH *pbvh, bool value);
 
 #define DYNTOPO_CD_INTERP
 
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 34597fb9be4..271a76ab8be 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -2062,7 +2062,7 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
   return pbvh;
 }
 
-//XXX hack
+// XXX hack
 extern SCULPT_dynamic_topology_sync_layers(Object *ob, Mesh *me);
 
 PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
@@ -2071,6 +2071,8 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
     return NULL;
   }
 
+  Scene *scene = DEG_get_input_scene(depsgraph);
+
   bool respect_hide = true;
   if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
     if (!(BKE_paint_select_vert_test(ob) || BKE_paint_select_face_test(ob))) {
@@ -2080,6 +2082,8 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
 
   PBVH *pbvh = ob->sculpt->pbvh;
   if (pbvh != NULL) {
+    SCULPT_update_flat_vcol_shading(ob, scene);
+
     /* NOTE: It is possible that grids were re-allocated due to modifier
      * stack. Need to update those pointers. */
     if (BKE_pbvh_type(pbvh) == PBVH_GRIDS) {
@@ -2115,6 +2119,11 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
   }
 
   ob->sculpt->pbvh = pbvh;
+
+  if (pbvh) {
+    SCULPT_update_flat_vcol_shading(ob, scene);
+  }
+
   return pbvh;
 }
 
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 92a9b433aff..fa9ed920fd5 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1019,6 +1019,7 @@ typedef struct PBVHUpdateData {
   float (*vnors)[3];
   int flag;
   bool show_sculpt_face_sets;
+  bool flat_vcol_shading;
 } PBVHUpdateData;
 
 static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
@@ -1336,12 +1337,30 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                       update_flags,
                                       pbvh->cd_vert_node_offset,
                                       pbvh->face_sets_color_seed,
-                                      pbvh->face_sets_color_default);
+                                      pbvh->face_sets_color_default,
+                                      data->flat_vcol_shading);
         break;
     }
   }
 }
 
+void BKE_pbvh_set_flat_vcol_shading(PBVH *pbvh, bool value)
+{
+  if (value != pbvh->flat_vcol_shading) {
+    for (int i = 0; i < pbvh->totnode; i++) {
+      PBVHNode *node = pbvh->nodes + i;
+
+      if (!(node->flag & PBVH_Leaf)) {
+        continue;
+      }
+
+      BKE_pbvh_node_mark_rebuild_draw(node);
+    }
+  }
+
+  pbvh->flat_vcol_shading = value;
+}
+
 static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag)
 {
   if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
@@ -1385,9 +1404,7 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
 
   /* Parallel creation and update of draw buffers. */
   PBVHUpdateData data = {
-      .pbvh = pbvh,
-      .nodes = nodes,
-  };
+      .pbvh = pbvh, .nodes = nodes, .flat_vcol_shading = pbvh->flat_vcol_shading};
 
   TaskParallelSettings settings;
   BKE_pbvh_parallel_range_settings(&settings, true, totnode);
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index be67d9962c1..8a0253facc8 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -188,6 +188,8 @@ struct PBVH {
 
   struct BMLog *bm_log;
   struct SubdivCCG *subdiv_ccg;
+
+  bool flat_vcol_shading;
 };
 
 /* pbvh.c */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 690303ddc73..9b3d9fc796d 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1604,7 +1604,10 @@ void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, Scul
  * Initialize a #SculptOrigVertData for accessing original vertex data;
  * handles #BMesh, #Mesh, and multi-resolution.
  */
-void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node, SculptUndoType type)
+void SCULPT_orig_vert_data_init(SculptOrigVertData *data,
+                                Object *ob,
+                                PBVHNode *node,
+                                SculptUndoType type)
 {
   SculptUndoNode *unode = NULL;
   data->ss = ob->sculpt;
@@ -6193,7 +6196,6 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
       BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
     }
 
-
     if (sculpt_brush_needs_normal(ss, brush)) {
       update_sculpt_normal(sd, ob, nodes, totnode);
     }
@@ -6441,7 +6443,7 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
       if (ss->bm) {
         float *co = BM_ELEM_CD_GET_VOID_P(vd.bm_vert, ss->cd_origco_offset);
         copy_v3_v3(val, co);
-        //copy_v3_v3(val, BM_log_original_vert_co(ss->bm_log, vd.bm_vert));
+        // copy_v3_v3(val, BM_log_original_vert_co(ss->bm_log, vd.bm_vert));
       }
       else {
         copy_v3_v3(val, orco[vd.i]);
@@ -8485,6 +8487,22 @@ static bool sculpt_no_multires_poll(bContext *C)
   return false;
 }
 
+/* checks if pbvh needs to sync its flat vcol shading flag with scene tool settings
+   scene and ob are allowd to be NULL (in which case nothing is done).
+*/
+void SCULPT_update_flat_vcol_shading(Object *ob, Scene *scene)
+{
+  if (!scene || !ob || !ob->sculpt || !ob->sculpt->pbvh) {
+    return;
+  }
+
+  if (ob->sculpt->pbvh) {
+    bool flat_vcol_shading = ((scene->toolsettings->sculpt->flags &
+                               SCULPT_DYNTOPO_FLAT_VCOL_SHADING) != 0);
+
+    BKE_pbvh_set_flat_vcol_shading(ob->sculpt->pbvh, flat_vcol_shading);
+  }
+}
 static int sculpt_symmetrize_exec(bContext *C, wmOperator *op)
 {
   Object *ob = CTX_data_active_object(C);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 7681e6f3623..773c7077ff8 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1172,3 +1172,5 @@ bool SCULPT_ensure_dyntopo_node_undo(struct Object *ob,
                                      struct PBVHNode *node,
                                      SculptUndoType type,
                                      int extraType);
+
+void SCULPT_update_flat_vcol_shading(struct Object *ob, struct Scene *scene);
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 7ca5d9145f5..50262148eb1 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -96,7 +96,8 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                    const int update_flags,
                                    const int cd_vert_node_offset,
                                    int face_sets_color_seed,
-                                   int face_sets_color_default);
+                                   int face_sets_color_default,
+                                   bool flat_vcol);
 
 void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
                                   struct SubdivCCG *subdiv_ccg,
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9c91d6dc3b8..cf334cac889 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -952,6 +952,204 @@ void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata)
   }
 }
 
+static void gpu_flat_vcol_make_vert(float co[3],
+                                    BMVert *v,
+                                    GPUVertBuf *vert_buf,
+                                    int v_index,
+                                    int cd_vcol_offset,
+                                    const float fno[3])
+{
+  MPropCol *mp = BM_ELEM_CD_GET_VOID_P(v, cd_vcol_offset);
+  ushort vcol[4];
+
+  // printf(
+  //    "%.2f %.2f %.2f %.2f\n", mp->color[0], mp->color[1], mp->color[2], mp->color[3]);
+  vcol[0] = unit_float_to_ushort_clamp(mp->color[0]);
+  vcol[1] = unit_float_to_ushort_clamp(mp->color[1]);
+  vcol[2] = unit_float_to_ushort_clamp(mp->color[2]);
+  vcol[3] = unit_float_to_ushort_clamp(mp->color[3]);
+
+  GPU_vertbuf_attr_set(vert_buf, g_vbo_id.col, v_index, vcol);
+
+  /* Set coord, normal, and mask */
+  GPU_vertbuf_attr_set(vert_buf, g_vbo_id.pos, v_index, co);
+
+  short no_short[3];
+
+  normal_float_to_short_v3(no_short, fno ? fno : v->no);
+  GPU_vertbuf_attr_set(vert_buf, g_vbo_id.nor, v_index, no_short);
+}
+
+/* Creates a vertex buffer (coordinate, normal, color) and, if smooth
+ * shading, an element index buffer.
+ * Threaded - do not call any functions that use OpenGL calls! */
+static void GPU_pbvh

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list