[Bf-blender-cvs] [097fb45a84e] temp-sculpt-normals-masking: temp-sculpt-normals-masking: Occlusion and initial normal masking

Joseph Eagar noreply at git.blender.org
Mon Jun 27 03:32:37 CEST 2022


Commit: 097fb45a84e042c420fcc74c73cdf17822aca881
Author: Joseph Eagar
Date:   Sun Jun 26 18:31:14 2022 -0700
Branches: temp-sculpt-normals-masking
https://developer.blender.org/rB097fb45a84e042c420fcc74c73cdf17822aca881

temp-sculpt-normals-masking: Occlusion and initial normal masking

Adds support for two normal masking modes: one that compares
with the view normal and another that compares with the
initial brush normal.  Both support falloffs.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.cc
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_enums.h
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 892dc9a1e42..102531426d2 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -970,7 +970,20 @@ 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="Initial Normal")
+        col.prop(sculpt, "use_automasking_view_normal", text="Occlusion")
+
+        if sculpt.use_automasking_start_normal:
+            col.separator()
+
+            col.prop(sculpt, "automasking_start_normal_limit")
+            col.prop(sculpt, "automasking_start_normal_falloff")
+
+        if sculpt.use_automasking_view_normal:
+            col.separator()
+
+            col.prop(sculpt, "automasking_view_normal_limit")
+            col.prop(sculpt, "automasking_view_normal_falloff")
 
 
 class VIEW3D_PT_sculpt_options_gravity(Panel, View3DPaintPanel):
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 8c91ea2b369..1531bdc6e31 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1968,6 +1968,14 @@ void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene)
     sd->constant_detail = 3.0f;
   }
 
+  if (!sd->automasking_start_normal_limit) {
+    sd->automasking_start_normal_limit = 20.0f / 180.0f * M_PI;
+    sd->automasking_start_normal_falloff = 0.25f;
+
+    sd->automasking_view_normal_limit = 90.0f / 180.0f * M_PI;
+    sd->automasking_view_normal_falloff = 0.25f;
+  }
+
   /* Set sane default tiling offsets */
   if (!sd->paint.tile_offset[0]) {
     sd->paint.tile_offset[0] = 1.0f;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 5ea42a5efa5..005987957b8 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1231,11 +1231,11 @@ static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush
 /**
  * Test whether the #StrokeCache.sculpt_normal needs update in #do_brush_action
  */
-static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
+static int sculpt_brush_needs_normal(const SculptSession *ss, Sculpt *sd, const Brush *brush)
 {
   return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool) &&
            (ss->cache->normal_weight > 0.0f)) ||
-
+          SCULPT_automasking_needs_normal(ss, sd, brush) ||
           ELEM(brush->sculpt_tool,
                SCULPT_TOOL_BLOB,
                SCULPT_TOOL_CREASE,
@@ -1288,7 +1288,10 @@ void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, Scul
   }
 }
 
-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;
   unode = SCULPT_undo_push_node(ob, node, type);
@@ -3344,7 +3347,7 @@ static void do_brush_action(Sculpt *sd,
     BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
   }
 
-  if (sculpt_brush_needs_normal(ss, brush)) {
+  if (sculpt_brush_needs_normal(ss, sd, brush)) {
     update_sculpt_normal(sd, ob, nodes, totnode);
   }
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
index bb101717c9b..5f5a3d774bb 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@ -87,6 +87,12 @@ bool SCULPT_is_automasking_enabled(const Sculpt *sd, const SculptSession *ss, co
   if (SCULPT_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS)) {
     return true;
   }
+  if (SCULPT_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_BRUSH_NORMAL)) {
+    return true;
+  }
+  if (SCULPT_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_VIEW_NORMAL)) {
+    return true;
+  }
   return false;
 }
 
@@ -98,6 +104,45 @@ static int sculpt_automasking_mode_effective_bits(const Sculpt *sculpt, const Br
   return sculpt->automasking_flags;
 }
 
+bool SCULPT_automasking_needs_normal(const SculptSession *ss,
+                                     const Sculpt *sculpt,
+                                     const Brush *brush)
+{
+  int flags = sculpt_automasking_mode_effective_bits(sculpt, brush);
+
+  return flags & (BRUSH_AUTOMASKING_BRUSH_NORMAL | BRUSH_AUTOMASKING_VIEW_NORMAL);
+}
+
+static float sculpt_automasking_normal_calc(AutomaskingCache *automasking,
+                                            SculptSession *ss,
+                                            int vertex,
+                                            const float normal[3],
+                                            float limit_lower,
+                                            float limit_upper)
+{
+  float normal_v[3];
+
+  SCULPT_vertex_normal_get(ss, vertex, normal_v);
+
+  float angle = saacos(dot_v3v3(normal, normal_v));
+
+  /* note that limit is pre-divided by M_PI */
+
+  if (angle > limit_lower && angle < limit_upper) {
+    float t = 1.0f - (angle - limit_lower) / (limit_upper - limit_lower);
+
+    /* smoothstep */
+    t = t * t * (3.0 - 2.0 * t);
+
+    return t;
+  }
+  else if (angle > limit_upper) {
+    return 0.0f;
+  }
+
+  return 1.0f;
+}
+
 static bool SCULPT_automasking_needs_factors_cache(const Sculpt *sd, const Brush *brush)
 {
 
@@ -144,7 +189,32 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking, SculptSession
     }
   }
 
-  return 1.0f;
+  float mask = 1.0f;
+
+  if (ss->cache && (automasking->settings.flags & BRUSH_AUTOMASKING_BRUSH_NORMAL)) {
+    float falloff = automasking->settings.start_normal_falloff * M_PI;
+
+    mask *= sculpt_automasking_normal_calc(
+        automasking,
+        ss,
+        vert,
+        ss->cache->initial_normal,
+        automasking->settings.start_normal_limit - falloff * 0.5f,
+        automasking->settings.start_normal_limit + falloff * 0.5f);
+  }
+
+  if (ss->cache && (automasking->settings.flags & BRUSH_AUTOMASKING_VIEW_NORMAL)) {
+    float falloff = automasking->settings.view_normal_falloff * M_PI;
+
+    mask *= sculpt_automasking_normal_calc(automasking,
+                                           ss,
+                                           vert,
+                                           ss->cache->view_normal,
+                                           automasking->settings.view_normal_limit,
+                                           automasking->settings.view_normal_limit + falloff);
+  }
+
+  return mask;
 }
 
 void SCULPT_automasking_cache_free(AutomaskingCache *automasking)
@@ -319,6 +389,12 @@ static void SCULPT_automasking_cache_settings_update(AutomaskingCache *automaski
 {
   automasking->settings.flags = sculpt_automasking_mode_effective_bits(sd, brush);
   automasking->settings.initial_face_set = SCULPT_active_face_set_get(ss);
+
+  automasking->settings.view_normal_limit = sd->automasking_view_normal_limit;
+  automasking->settings.view_normal_falloff = sd->automasking_view_normal_falloff;
+  automasking->settings.start_normal_limit = sd->automasking_start_normal_limit;
+  automasking->settings.start_normal_falloff = sd->automasking_start_normal_falloff;
+  automasking->settings.use_original_normal = sd->automasking_use_original_normal;
 }
 
 AutomaskingCache *SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object *ob)
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index e8a2d35ccd0..e0b608dce75 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -394,6 +394,9 @@ typedef struct AutomaskingSettings {
   /* Flags from eAutomasking_flag. */
   int flags;
   int initial_face_set;
+  float start_normal_limit, start_normal_falloff;
+  float view_normal_limit, view_normal_falloff;
+  bool use_original_normal;
 } AutomaskingSettings;
 
 typedef struct AutomaskingCache {
@@ -1288,6 +1291,10 @@ float *SCULPT_boundary_automasking_init(Object *ob,
                                         eBoundaryAutomaskMode mode,
                                         int propagation_steps,
                                         float *automask_factor);
+
+bool SCULPT_automasking_needs_normal(const SculptSession *ss,
+                                     const Sculpt *sculpt,
+                                     const Brush *brush);
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index f2cd49b6dea..00af35bc70d 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -318,6 +318,9 @@ typedef enum eAutomasking_flag {
   BRUSH_AUTOMASKING_FACE_SETS = (1 << 1),
   BRUSH_AUTOMASKING_BOUNDARY_EDGES = (1 << 2),
   BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS = (1 << 3),
+  BRUSH_AUTOMASKING_BRUSH_NORMAL = (1 << 8),
+  BRUSH_AUTOMASKING_VIEW_NORMAL = (1 << 9),
+
 } eAutomasking_flag;
 
 typedef enum ePaintBrush_flag {
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 1c62a550e60..655d896db62 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1016,6 +1016,9 @@ typedef struct Sculpt {
 
   char _pad[4];
 
+  float automasking_start_normal_limit, automasking_start_normal_falloff;
+  float automasking_view_normal_limit, automasking_view_normal_falloff;
+
   struct Object *gravity_object;
 } Scu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list