[Bf-blender-cvs] [3f803851188] temp-sculpt-normals-masking: temp-sculpt-normals-masking: Use a stroke id attribute for occlusion

Joseph Eagar noreply at git.blender.org
Thu Sep 22 20:29:48 CEST 2022


Commit: 3f803851188397e9697695e80bc8467ac839ec66
Author: Joseph Eagar
Date:   Thu Sep 22 11:28:16 2022 -0700
Branches: temp-sculpt-normals-masking
https://developer.blender.org/rB3f803851188397e9697695e80bc8467ac839ec66

temp-sculpt-normals-masking: Use a stroke id attribute for occlusion

Use a stroke id temp attribute to keep track of which verts
need occlusion tests.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.cc
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_filter_color.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 4b5da913fe2..34e93966b19 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -953,13 +953,13 @@ def brush_settings_advanced(layout, context, brush, popover=False):
         if brush.use_automasking_start_normal:
             col.separator()
 
-            col.prop(brush, "use_automasking_view_occlusion", text="Occlusion")
             col.prop(sculpt, "automasking_start_normal_limit")
             col.prop(sculpt, "automasking_start_normal_falloff")
 
         if brush.use_automasking_view_normal:
             col.separator()
 
+            col.prop(brush, "use_automasking_view_occlusion", text="Occlusion")
             col.prop(sculpt, "automasking_view_normal_limit")
             col.prop(sculpt, "automasking_view_normal_falloff")
 
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index ffe9f45442a..7518e7171a8 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -5492,6 +5492,7 @@ class VIEW3D_MT_sculpt_automasking_pie(Menu):
         pie.prop(sculpt, "use_automasking_topology", text="Topology")
         pie.prop(sculpt, "use_automasking_face_sets", text="Face Sets")
         pie.prop(sculpt, "use_automasking_boundary_edges", text="Mesh Boundary")
+        pie.prop(sculpt, "use_automasking_boundary_face_sets", text="Face Sets Boundary")
         pie.prop(sculpt, "use_automasking_start_normal", text="Area Normal")
         pie.prop(sculpt, "use_automasking_view_normal", text="View Normal")
 
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index ecac5c2ffd5..94961112bab 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -970,6 +970,7 @@ class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
         col.prop(sculpt, "use_automasking_topology", text="Topology")
         col.prop(sculpt, "use_automasking_face_sets", text="Face Sets")
         col.prop(sculpt, "use_automasking_boundary_edges", text="Mesh Boundary")
+        col.prop(sculpt, "use_automasking_boundary_face_sets", text="Face Sets Boundary")
         col.prop(sculpt, "use_automasking_start_normal", text="Area Normal")
         col.prop(sculpt, "use_automasking_view_normal", text="View Normal")
         
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 8895200455e..145b2775377 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -548,10 +548,13 @@ typedef struct SculptAttributePointers {
   /* Precomputed auto-mask factor indexed by vertex, owned by the auto-masking system and
    * initialized in #SCULPT_automasking_cache_init when needed. */
   SculptAttribute *automasking_factor;
+  SculptAttribute *automasking_occlusion; /* CD_PROP_INT8. */
 
   /* BMesh */
   SculptAttribute *dyntopo_node_id_vertex;
   SculptAttribute *dyntopo_node_id_face;
+
+  SculptAttribute *stroke_id;
 } SculptAttributePointers;
 
 typedef struct SculptSession {
@@ -744,6 +747,7 @@ typedef struct SculptSession {
   char *last_paint_canvas_key;
 
   float last_normal[3];
+  int stroke_id;
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 1b5299849ad..58ebe56df89 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4236,6 +4236,7 @@ static void sculpt_update_cache_invariants(
   int mode;
 
   ss->cache = cache;
+  ss->stroke_id++;
 
   /* Set scaling adjustment. */
   max_scale = 0.0f;
@@ -6063,4 +6064,16 @@ bool SCULPT_vertex_is_occluded(SculptSession *ss, PBVHVertRef vertex, bool origi
   return srd.hit;
 }
 
+void SCULPT_stroke_id_ensure(Object *ob)
+{
+  SculptSession *ss = ob->sculpt;
+
+  if (!ss->attrs.stroke_id) {
+    SculptAttributeParams params = {0};
+    
+    ss->attrs.stroke_id = BKE_sculpt_attribute_ensure(
+        ob, ATTR_DOMAIN_POINT, CD_PROP_INT32, SCULPT_ATTRIBUTE_NAME(stroke_id), &params);
+  }
+}
+
 /** \} */
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 2707d4fd938..e8ca92cdd6d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@ -217,19 +217,30 @@ static float automasking_view_normal_factor(AutomaskingCache *automasking,
 static float automasking_view_occlusion_factor(AutomaskingCache *automasking,
                                                SculptSession *ss,
                                                PBVHVertRef vertex,
+                                               int stroke_id,
                                                AutomaskingNodeData *automask_data)
 {
-  int index = BKE_pbvh_vertex_to_index(ss->pbvh, vertex);
+  char f = *(char *)SCULPT_vertex_attr_get(vertex, ss->attrs.automasking_occlusion);
 
-  char f = *(char *)SCULPT_vertex_attr_get(vertex, automasking->occlusion_attr);
-
-  if (!f) {
-    f = *(char *)SCULPT_vertex_attr_get(vertex, automasking->occlusion_attr) = SCULPT_vertex_is_occluded(ss, vertex, true) ? 2 : 1;
+  if (stroke_id != ss->stroke_id) {
+    f = *(char *)SCULPT_vertex_attr_get(
+        vertex,
+        ss->attrs.automasking_occlusion) = SCULPT_vertex_is_occluded(ss, vertex, true) ? 2 : 1;
   }
 
   return f == 2;
 }
 
+/* Updates vertex stroke id. */
+static float automasking_factor_end(SculptSession *ss, PBVHVertRef vertex, float value)
+{
+  if (ss->attrs.stroke_id) {
+    *(int *)SCULPT_vertex_attr_get(vertex, ss->attrs.stroke_id) = ss->stroke_id;
+  }
+
+  return value;
+}
+
 float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
                                     SculptSession *ss,
                                     PBVHVertRef vert,
@@ -246,28 +257,33 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
     return *(float *)SCULPT_vertex_attr_get(vert, ss->attrs.automasking_factor);
   }
 
+  int stroke_id = ss->attrs.stroke_id ?
+                      *(int *)(SCULPT_vertex_attr_get(vert, ss->attrs.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, automask_data)) {
-    return 0.0f;
+  if (do_occlusion &&
+      automasking_view_occlusion_factor(automasking, ss, vert, stroke_id, automask_data)) {
+    return automasking_factor_end(ss, vert, 0.0f);
   }
 
   if (automasking->settings.flags & BRUSH_AUTOMASKING_FACE_SETS) {
     if (!SCULPT_vertex_has_face_set(ss, vert, automasking->settings.initial_face_set)) {
-      return 0.0f;
+      return automasking_factor_end(ss, vert, 0.0f);
     }
   }
 
   if (automasking->settings.flags & BRUSH_AUTOMASKING_BOUNDARY_EDGES) {
     if (SCULPT_vertex_is_boundary(ss, vert)) {
-      return 0.0f;
+      return automasking_factor_end(ss, vert, 0.0f);
     }
   }
 
   if (automasking->settings.flags & BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS) {
     if (!SCULPT_vertex_has_unique_face_set(ss, vert)) {
-      return 0.0f;
+      return automasking_factor_end(ss, vert, 0.0f);
     }
   }
 
@@ -283,7 +299,7 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
     mask *= automasking_view_normal_factor(automasking, ss, vert, automask_data);
   }
 
-  return mask;
+  return automasking_factor_end(ss, vert, mask);
 }
 
 void SCULPT_automasking_cache_free(AutomaskingCache *automasking)
@@ -492,12 +508,13 @@ void sculpt_normal_occlusion_automasking_fill(AutomaskingCache *automasking,
     }
     if ((int)mode & BRUSH_AUTOMASKING_VIEW_NORMAL) {
       if ((int)mode & BRUSH_AUTOMASKING_VIEW_OCCLUSION) {
-        f *= automasking_view_occlusion_factor(automasking, ss, vertex, &nodedata);
+        f *= automasking_view_occlusion_factor(automasking, ss, vertex, -1, &nodedata);
       }
 
       f *= automasking_view_normal_factor(automasking, ss, vertex, &nodedata);
     }
 
+    *(int *)SCULPT_vertex_attr_get(vertex, ss->attrs.stroke_id) = ss->stroke_id;
     *(float *)SCULPT_vertex_attr_get(vertex, ss->attrs.automasking_factor) = f;
   }
 }
@@ -517,11 +534,17 @@ AutomaskingCache *SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object
   SCULPT_boundary_info_ensure(ob);
 
   if (sculpt_automasking_mode_effective_bits(sd, brush) & BRUSH_AUTOMASKING_VIEW_OCCLUSION) {
-    SculptAttributeParams params = {0};
-
-    params.stroke_only = true;
-    automasking->occlusion_attr = BKE_sculpt_attribute_ensure(
-        ob, ATTR_DOMAIN_POINT, CD_PROP_INT8, ".sculpt.automasking_occlusion", &params);
+    SCULPT_stroke_id_ensure(ob);
+
+    if (!ss->attrs.automasking_occlusion) {
+      SculptAttributeParams params = {0};
+      ss->attrs.automasking_occlusion = BKE_sculpt_attribute_ensure(
+          ob,
+          ATTR_DOMAIN_POINT,
+          CD_PROP_INT8,
+          SCULPT_ATTRIBUTE_NAME(automasking_occlusion),
+          &params);
+    }
   }
 
   if (!SCULPT_automasking_needs_factors_cache(sd, brush)) {
@@ -558,8 +581,7 @@ AutomaskingCache *SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object
                      BRUSH_AUTOMASKING_VIEW_OCCLUSION);
 
   if (normal_bits) {
-    sculpt_normal_occlusion_automasking_fill(
-        automasking, ob, (eAutomasking_flag)normal_bits);
+    sculpt_normal_occlusion_automasking_fill(automasking, ob, (eAutomasking_flag)normal_bits);
   }
 
   if (SCULPT_is_automasking_mode_enabled(sd, brush, BRUSH_AUTOMASKING_BOUNDARY_EDGES)) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 72b0b3a97fe..533e2

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list