[Bf-blender-cvs] [b955416beee] temp-pbvh-texpaint-automasking: temp-pbvh-texpaint-automasking: Fix merge errors

Joseph Eagar noreply at git.blender.org
Tue Oct 11 20:34:04 CEST 2022


Commit: b955416beee48020f69f8a89c40f437f5c9edb5e
Author: Joseph Eagar
Date:   Tue Oct 11 11:29:57 2022 -0700
Branches: temp-pbvh-texpaint-automasking
https://developer.blender.org/rBb955416beee48020f69f8a89c40f437f5c9edb5e

temp-pbvh-texpaint-automasking: Fix merge errors

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

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/editors/sculpt_paint/sculpt_automasking.cc
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index e314d9263bd..0aec9565c2e 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -561,7 +561,7 @@ typedef struct PBVHVertexIter {
   float (*vert_normals)[3];
 
   const bool *hide_vert;
-  int totvert, unique_verts;
+  int totvert, unique_verts_count;
   const int *vert_indices;
   float *vmask;
 
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index f2b74f67506..18b72c2334d 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3076,7 +3076,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
     vi->totvert = uniq_verts;
   }
 
-  vi->unique_verts = uniq_verts;
+  vi->unique_verts_count = uniq_verts;
 
   vi->vert_indices = vert_indices;
   vi->mverts = verts;
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 368a9ffa1ea..2a294e5bf82 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -96,7 +96,7 @@ struct PBVHNode {
 
   /* Indicates whether this node is a leaf or not; also used for
    * marking various updates that need to be applied. */
-  PBVHNodeFlags flag : 32;
+  PBVHNodeFlags flag;
 
   /* Used for raycasting: how close bb is to the ray point. */
   float tmin;
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 0b434d16797..d0a46e0ebce 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@ -499,41 +499,6 @@ static float sculpt_automasking_cavity_factor(AutomaskingCache *automasking,
   return factor;
 }
 
-float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
-                                    SculptSession *ss,
-                                    PBVHVertRef vert,
-                                    AutomaskingNodeData *automask_data)
-{
-  if (!automasking || vert.i == PBVH_REF_NONE) {
-    return 1.0f;
-  }
-
-  /* If the cache is initialized with valid info, use the cache. This is used when the
-   * automasking information can't be computed in real time per vertex and needs to be
-   * initialized for the whole mesh when the stroke starts. */
-  if (ss->attrs.automasking_factor) {
-    float factor = *(float *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_factor);
-
-    if (automasking->settings.flags & BRUSH_AUTOMASKING_CAVITY_ALL) {
-      factor *= sculpt_automasking_cavity_factor(automasking, ss, vert);
-    }
-
-    return factor;
-  }
-
-  uchar stroke_id = ss->attrs.automasking_stroke_id ?
-                        *(uchar *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_stroke_id) :
-                        -1;
-
-  bool do_occlusion = (automasking->settings.flags &
-                       (BRUSH_AUTOMASKING_VIEW_OCCLUSION | BRUSH_AUTOMASKING_VIEW_NORMAL)) ==
-                      (BRUSH_AUTOMASKING_VIEW_OCCLUSION | BRUSH_AUTOMASKING_VIEW_NORMAL);
-  if (do_occlusion &&
-      automasking_view_occlusion_factor(automasking, ss, vert, stroke_id, automask_data)) {
-    return automasking_factor_end(ss, automasking, vert, 0.0f);
-  }
-}
-
 float sculpt_automasking_factor_calc(AutomaskingCache *automasking,
                                      SculptSession *ss,
                                      PBVHVertRef vert,
@@ -581,14 +546,33 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
                                     PBVHVertRef vert,
                                     AutomaskingNodeData *automask_data)
 {
-  if (!automasking) {
+  if (!automasking || vert.i == PBVH_REF_NONE) {
     return 1.0f;
   }
+
   /* If the cache is initialized with valid info, use the cache. This is used when the
    * automasking information can't be computed in real time per vertex and needs to be
    * initialized for the whole mesh when the stroke starts. */
   if (automasking->has_full_factor_cache) {
-    return *(float *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_factor);
+    float factor = *(float *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_factor);
+
+    if (automasking->settings.flags & BRUSH_AUTOMASKING_CAVITY_ALL) {
+      factor *= sculpt_automasking_cavity_factor(automasking, ss, vert);
+    }
+
+    return factor;
+  }
+
+  uchar stroke_id = ss->attrs.automasking_stroke_id ?
+                        *(uchar *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_stroke_id) :
+                        -1;
+
+  bool do_occlusion = (automasking->settings.flags &
+                       (BRUSH_AUTOMASKING_VIEW_OCCLUSION | BRUSH_AUTOMASKING_VIEW_NORMAL)) ==
+                      (BRUSH_AUTOMASKING_VIEW_OCCLUSION | BRUSH_AUTOMASKING_VIEW_NORMAL);
+  if (do_occlusion &&
+      automasking_view_occlusion_factor(automasking, ss, vert, stroke_id, automask_data)) {
+    return automasking_factor_end(ss, automasking, vert, 0.0f);
   }
 
   return sculpt_automasking_factor_calc(automasking, ss, vert, automask_data);
@@ -845,18 +829,6 @@ AutomaskingCache *SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object
   SCULPT_automasking_cache_settings_update(automasking, ss, sd, brush);
   SCULPT_boundary_info_ensure(ob);
 
-  if (!SCULPT_automasking_needs_factors_cache(sd, brush) && ss->cache && ss->cache->use_pixels) {
-    /*
-     * Allocate factor cache but don't initialize it.
-     * Will be filled in by SCULPT_automasking_cache_check.
-     */
-    ss->attrs.automasking_factor = BKE_sculpt_attribute_ensure(
-        ob, ATTR_DOMAIN_POINT, CD_PROP_FLOAT, SCULPT_ATTRIBUTE_NAME(automasking_factor), &params);
-    automasking->current_stroke_id = ss->stroke_id;
-
-    return automasking;
-  }
-
   automasking->current_stroke_id = ss->stroke_id;
 
   bool use_stroke_id = false;
@@ -915,6 +887,20 @@ AutomaskingCache *SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object
     }
   }
 
+  if (!SCULPT_automasking_needs_factors_cache(sd, brush) && ss->cache && ss->cache->use_pixels) {
+    SculptAttributeParams params = {0};
+    params.stroke_only = true;
+
+    /*
+     * Allocate factor cache but don't initialize it.
+     * Will be filled in by SCULPT_automasking_cache_check.
+     */
+    ss->attrs.automasking_factor = BKE_sculpt_attribute_ensure(
+        ob, ATTR_DOMAIN_POINT, CD_PROP_FLOAT, SCULPT_ATTRIBUTE_NAME(automasking_factor), &params);
+
+    return automasking;
+  }
+
   if (!SCULPT_automasking_needs_factors_cache(sd, brush)) {
     return automasking;
   }
@@ -1005,11 +991,12 @@ void SCULPT_automasking_cache_check(
       PBVHVertexIter vd;
       AutomaskingNodeData automask_data;
 
-      SCULPT_automasking_node_begin(ob, ss, automasking, &automask_data);
+      SCULPT_automasking_node_begin(ob, ss, automasking, &automask_data, nodes[i]);
+
       BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_ALL) {
         SCULPT_automasking_node_update(ss, &automask_data, &vd);
 
-        if (vd.i >= vd.unique_verts) {
+        if (vd.i >= vd.unique_verts_count) {
           node_other_verts[i].append(vd.vertex);
         }
         else {
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 9bf9f8c9601..a99c57ac145 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1877,7 +1877,8 @@ void SCULPT_OT_brush_stroke(struct wmOperatorType *ot);
 
 /* end sculpt_ops.c */
 
-void SCULPT_automasking_cache_check(struct Objedct *ob,
+/* Update automasking factor cache incrementally; currently used only by texture paint. */
+void SCULPT_automasking_cache_check(struct Object *ob,
                                     struct SculptSession *ss,
                                     struct AutomaskingCache *automasking,
                                     struct PBVHNode **nodes,
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index 3a40e7ad248..ddb806690dd 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -126,9 +126,30 @@ static float paint_automasking_interp(SculptSession *ss,
     return 1.0f;
   }
 
-  float a = SCULPT_automasking_factor_get(ss->cache->automasking, ss, triangle.vert_indices[0]);
-  float b = SCULPT_automasking_factor_get(ss->cache->automasking, ss, triangle.vert_indices[1]);
-  float c = SCULPT_automasking_factor_get(ss->cache->automasking, ss, triangle.vert_indices[2]);
+  AutomaskingNodeData automask_data = {};
+  automask_data.have_orig_data = false;
+
+  PBVHVertRef v1, v2, v3;
+
+  /* Not sure we need to use BKE_pbvh_index_to_vertex if texture paint
+   * only works in PBVH_FACES, at least for now.
+   */
+
+  BLI_assert(BKE_pbvh_type(ss->pbvh) == PBVH_FACES);
+
+#if 0
+  v1 = BKE_pbvh_index_to_vertex(ss->pbvh, triangle.vert_indices[0]);
+  v2 = BKE_pbvh_index_to_vertex(ss->pbvh, triangle.vert_indices[1]);
+  v3 = BKE_pbvh_index_to_vertex(ss->pbvh, triangle.vert_indices[2]);
+#else
+  v1.i = triangle.vert_indices[0];
+  v2.i = triangle.vert_indices[1];
+  v3.i = triangle.vert_indices[2];
+#endif
+
+  float a = SCULPT_automasking_factor_get(ss->cache->automasking, ss, v1, &automask_data);
+  float b = SCULPT_automasking_factor_get(ss->cache->automasking, ss, v2, &automask_data);
+  float c = SCULPT_automasking_factor_get(ss->cache->automasking, ss, v3, &automask_data);
 
   return a * uv[0] + b * uv[1] + c * (1.0 - uv[0] - uv[1]);
 }
@@ -341,8 +362,8 @@ static void do_paint_pixels(void *__restrict userdata,
   PaintingKernel<ImageBufferFloat4> kernel_float4(ss, brush, thread_id, mvert);
   PaintingKernel<ImageBufferByte4> kernel_byte4(ss, brush, thread_id, mvert);
 
-  AutomaskingNodeData automask_data;
-  SCULPT_automasking_node_begin(ob, ss, ss->cache->automasking, &automask_data, data->nodes[n]);
+  AutomaskingNodeData automask_data = {0};
+  automask_data.have_orig_data = fals

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list