[Bf-blender-cvs] [7ec7fa03ea8] temp-sculpt-colors: temp-sculpt-colors: make requested changes

Joseph Eagar noreply at git.blender.org
Sun Apr 3 19:30:41 CEST 2022


Commit: 7ec7fa03ea81814781e1b86113dd22d91bd087f8
Author: Joseph Eagar
Date:   Sun Apr 3 10:28:48 2022 -0700
Branches: temp-sculpt-colors
https://developer.blender.org/rB7ec7fa03ea81814781e1b86113dd22d91bd087f8

temp-sculpt-colors: make requested changes

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

M	source/blender/blenkernel/BKE_attribute.h
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/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c

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

diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 8c89a925064..e085b96525c 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -104,7 +104,7 @@ void BKE_id_attribute_subset_active_set(struct ID *id,
 
 /**
  * Copies CustomData instances into a (usually stack-allocated) ID.  This is a shallow copy, the
- * purpose is to create a bride for using the C attribute API on arbitrary sets of CustomData
+ * purpose is to create a bridge for using the C attribute API on arbitrary sets of CustomData
  * domains.
  */
 void BKE_id_attribute_copy_domains_temp(struct ID *temp_id,
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index ab58b6f8599..5d307697208 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3143,7 +3143,7 @@ void BKE_pbvh_node_num_loops(PBVH *pbvh, PBVHNode *node, int *r_totloop)
   BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
 
   if (r_totloop) {
-    *r_totloop = node->indices_num;
+    *r_totloop = node->loop_indices_num;
   }
 }
 
@@ -3189,14 +3189,14 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh)
     }
 
     node->loop_indices = MEM_malloc_arrayN(node->totprim * 3, sizeof(int), __func__);
-    node->indices_num = 0;
+    node->loop_indices_num = 0;
 
     for (int j = 0; j < node->totprim; j++) {
       const MLoopTri *mlt = pbvh->looptri + node->prim_indices[j];
 
       for (int k = 0; k < 3; k++) {
         if (!BLI_BITMAP_TEST(visit, mlt->tri[k])) {
-          node->loop_indices[node->indices_num++] = mlt->tri[k];
+          node->loop_indices[node->loop_indices_num++] = mlt->tri[k];
           BLI_BITMAP_ENABLE(visit, mlt->tri[k]);
         }
       }
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 058b9ff9120..72ace096db7 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -67,7 +67,7 @@ struct PBVHNode {
    * are loops unique to this node, see comment for
    * vert_indices for more details.*/
   int *loop_indices;
-  unsigned int indices_num;
+  unsigned int loop_indices_num;
 
   /* An array mapping face corners into the vert_indices
    * array. The array is sized to match 'totprim', and each of
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index dbdf5acf505..e97d52190f1 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -157,7 +157,7 @@ bool SCULPT_has_colors(const SculptSession *ss)
   return ss->vcol || ss->mcol;
 }
 
-void SCULPT_vertex_color_get(SculptSession *ss, int index, float r_color[4])
+void SCULPT_vertex_color_get(const SculptSession *ss, int index, float r_color[4])
 {
   BKE_pbvh_vertex_color_get(ss->pbvh, index, r_color);
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index bdc5e8e689c..c7b03458b31 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -868,9 +868,13 @@ const float *SCULPT_vertex_co_get(struct SculptSession *ss, int index);
 void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3]);
 
 float SCULPT_vertex_mask_get(struct SculptSession *ss, int index);
-void SCULPT_vertex_color_get(SculptSession *ss, int index, float r_color[4]);
+void SCULPT_vertex_color_get(const SculptSession *ss, int index, float r_color[4]);
 void SCULPT_vertex_color_set(SculptSession *ss, int index, const float color[4]);
+
+/** Returns true if a color attribute exists in the current sculpt session. */
 bool SCULPT_has_colors(const SculptSession *ss);
+
+/** Returns true if the active color attribute is on loop (ATTR_DOMAIN_CORNER) domain. */
 bool SCULPT_has_loop_colors(const struct Object *ob);
 
 const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index);
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index c821124d947..cc4392c6a8a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
@@ -158,7 +158,7 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
     float noise = 1.0f;
     const float density = ss->cache->paint_brush.density;
     if (density < 1.0f) {
-      const float hash_noise = BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index);
+      const float hash_noise = (float) BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index);
       if (hash_noise > density) {
         noise = density * hash_noise;
         fade = fade * noise;
@@ -251,7 +251,7 @@ void SCULPT_do_paint_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
 
   if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) {
     if (SCULPT_stroke_is_first_brush_step(ss->cache)) {
-      ss->cache->density_seed = BLI_hash_int_01(ss->cache->location[0] * 1000);
+      ss->cache->density_seed = (float) BLI_hash_int_01(ss->cache->location[0] * 1000);
     }
     return;
   }
@@ -417,8 +417,16 @@ static void do_smear_brush_task_cb_exec(void *__restrict userdata,
     float accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
     float totw = 0.0f;
 
-    SculptVertexNeighborIter ni2;
+    /*
+     * NOTE: we have to do a nested iteration here to avoid
+     * blocky artifacts on quad topologies.  The runtime cost
+     * is not as bad as it seems due to neighbor iteration
+     * in the sculpt code being cache bound; once the data is in
+     * the cache iterating over it a few more times is not terribly
+     * costly.
+     */
 
+    SculptVertexNeighborIter ni2;
     SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd.index, ni2) {
       const float *nco = SCULPT_vertex_co_get(ss, ni2.index);
 
@@ -499,10 +507,7 @@ static void do_smear_store_prev_colors_task_cb_exec(void *__restrict userdata,
 
   PBVHVertexIter vd;
   BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
-    float tmp[4] = {0};
-
-    SCULPT_vertex_color_get(ss, vd.index, tmp);
-    copy_v4_v4(ss->cache->prev_colors[vd.index], tmp);
+    SCULPT_vertex_color_get(ss, vd.index, ss->cache->prev_colors[vd.index]);
   }
   BKE_pbvh_vertex_iter_end;
 }
@@ -522,10 +527,7 @@ void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
     if (!ss->cache->prev_colors) {
       ss->cache->prev_colors = MEM_callocN(sizeof(float[4]) * totvert, "prev colors");
       for (int i = 0; i < totvert; i++) {
-        float tmp[4] = {0};
-
-        SCULPT_vertex_color_get(ss, i, tmp);
-        copy_v4_v4(ss->cache->prev_colors[i], tmp);
+        SCULPT_vertex_color_get(ss, i, ss->cache->prev_colors[i]);
       }
     }
   }
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 9af23424eb6..1354277fbdd 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -342,7 +342,7 @@ static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode)
 
   bool modified = false;
 
-  /* Note: even with loop colors we still store derived
+  /* NOTE: even with loop colors we still store derived
    * vertex colors for original data lookup.*/
   if (unode->col && !unode->loop_col) {
     BKE_pbvh_swap_colors(ss->pbvh, unode->index, unode->totvert, unode->col);
@@ -1113,11 +1113,11 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
 
       /* Allocate loop colors separately too. */
       if (ss->vcol_domain == ATTR_DOMAIN_CORNER) {
-        size_t alloc_size2 = sizeof(float) * 4 * (size_t)unode->totloop;
+        size_t alloc_size_loop = sizeof(float) * 4 * (size_t)unode->totloop;
 
         unode->loop_col = MEM_calloc_arrayN(
             unode->totloop, sizeof(float) * 4, "SculptUndoNode.loop_col");
-        usculpt->undo_size += alloc_size2;
+        usculpt->undo_size += alloc_size_loop;
       }
       break;
     }
@@ -1220,7 +1220,7 @@ static void sculpt_undo_store_color(Object *ob, SculptUndoNode *unode)
   int allvert;
   BKE_pbvh_node_num_verts(ss->pbvh, unode->node, NULL, &allvert);
 
-  /* Note: even with loop colors we still store (derived)
+  /* NOTE: even with loop colors we still store (derived)
    * vertex colors for original data lookup. */
   BKE_pbvh_store_colors_vertex(ss->pbvh, unode->index, allvert, unode->col);



More information about the Bf-blender-cvs mailing list