[Bf-blender-cvs] [d7798025631] temp-sculpt-normals-masking: temp-sculpt-normals-masking: Add occlusion mode

Joseph Eagar noreply at git.blender.org
Thu Jul 28 19:13:54 CEST 2022


Commit: d77980256319e2c896e7949b745996b7dbe3e3bf
Author: Joseph Eagar
Date:   Mon Jul 25 13:50:55 2022 -0700
Branches: temp-sculpt-normals-masking
https://developer.blender.org/rBd77980256319e2c896e7949b745996b7dbe3e3bf

temp-sculpt-normals-masking: Add occlusion mode

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

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/intern/pbvh.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/makesrna/intern/rna_brush.c
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 52551aedb1e..47c38d116f8 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -947,6 +947,7 @@ def brush_settings_advanced(layout, context, brush, popover=False):
 
         col.prop(brush, "use_automasking_start_normal", text="Area Normal")
         col.prop(brush, "use_automasking_view_normal", text="View Normal")
+        col.prop(brush, "use_automasking_view_occlusion", text="Occlusion")
 
         sculpt = context.tool_settings.sculpt
 
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 92dc4138530..eaf889c1bd4 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -5473,7 +5473,9 @@ 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")
+        pie.prop(sculpt, "use_automasking_view_occlusion", text="Occlusion")
 
 
 class VIEW3D_MT_sculpt_face_sets_edit_pie(Menu):
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index f0a99ea0979..7b1b02ef905 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -972,6 +972,7 @@ class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
         col.prop(sculpt, "use_automasking_boundary_edges", text="Mesh Boundary")
         col.prop(sculpt, "use_automasking_start_normal", text="Area Normal")
         col.prop(sculpt, "use_automasking_view_normal", text="View Normal")
+        col.prop(sculpt, "use_automasking_view_occlusion", text="Occlusion")
 
         if sculpt.use_automasking_start_normal:
             col.separator()
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 00a4eee47e3..13a67080a17 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -37,7 +37,7 @@
 
 #include <limits.h>
 
-#define LEAF_LIMIT 10000
+#define LEAF_LIMIT 400
 
 //#define PERFCNTRS
 
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 9d307a52998..7ab5571c20c 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5942,4 +5942,37 @@ void SCULPT_automasking_node_update(SculptSession *ss,
   }
 }
 
+bool SCULPT_vertex_is_occluded(SculptSession *ss, int vertex, bool original)
+{
+  float ray_start[3], ray_end[3], ray_normal[3], face_normal[3];
+  float co[3];
+
+  copy_v3_v3(co, SCULPT_vertex_co_get(ss, vertex));
+  float mouse[2];
+
+  ED_view3d_project_float_v2_m4(ss->cache->vc->region, co, mouse, ss->cache->projection_mat);
+
+  int depth = SCULPT_raycast_init(
+      ss->cache->vc, mouse, ray_end, ray_start, ray_normal, original);
+
+  negate_v3(ray_normal);
+
+  copy_v3_v3(ray_start, SCULPT_vertex_co_get(ss, vertex));
+  madd_v3_v3fl(ray_start, ray_normal, 0.002);
+
+  SculptRaycastData srd = {0};
+  srd.original = original;
+  srd.ss = ss;
+  srd.hit = false;
+  srd.ray_start = ray_start;
+  srd.ray_normal = ray_normal;
+  srd.depth = depth;
+  srd.face_normal = face_normal;
+
+  isect_ray_tri_watertight_v3_precalc(&srd.isect_precalc, ray_normal);
+  BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original);
+
+  return srd.hit;
+}
+
 /** \} */
diff --git a/source/blender/editors/sculpt_paint/sculpt_automasking.cc b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 7d1d60cbcff..26955c4bb8e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@ -93,6 +93,9 @@ bool SCULPT_is_automasking_enabled(const Sculpt *sd, const SculptSession *ss, co
   if (SCULPT_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_VIEW_NORMAL)) {
     return true;
   }
+  if (SCULPT_is_automasking_mode_enabled(sd, br, BRUSH_AUTOMASKING_VIEW_OCCLUSION)) {
+    return true;
+  }
   return false;
 }
 
@@ -180,6 +183,15 @@ float SCULPT_automasking_factor_get(AutomaskingCache *automasking,
   if (automasking->factor) {
     return automasking->factor[vert];
   }
+  if (automasking->settings.flags & BRUSH_AUTOMASKING_VIEW_OCCLUSION) {
+    if (!automasking->occluded[vert]) {
+      automasking->occluded[vert] = SCULPT_vertex_is_occluded(ss, vert, true) ? 2 : 1;
+    }
+
+    if (automasking->occluded[vert] - 1) {
+      return 0.0f;
+    }
+  }
 
   if (automasking->settings.flags & BRUSH_AUTOMASKING_FACE_SETS) {
     if (!SCULPT_vertex_has_face_set(ss, vert, automasking->settings.initial_face_set)) {
@@ -255,6 +267,7 @@ void SCULPT_automasking_cache_free(AutomaskingCache *automasking)
   }
 
   MEM_SAFE_FREE(automasking->factor);
+  MEM_SAFE_FREE(automasking->occluded);
   MEM_SAFE_FREE(automasking);
 }
 
@@ -441,6 +454,10 @@ 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_is_automasking_mode_enabled(sd, brush, BRUSH_AUTOMASKING_VIEW_OCCLUSION)) {
+    automasking->occluded = (char *)MEM_callocN(totvert, "automasking->occluded");
+  }
+
   if (!SCULPT_automasking_needs_factors_cache(sd, brush)) {
     return automasking;
   }
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 8910e08d29d..7fb8c5657fc 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -404,6 +404,7 @@ typedef struct AutomaskingCache {
   /* Precomputed auto-mask factor indexed by vertex, owned by the auto-masking system and
    * initialized in #SCULPT_automasking_cache_init when needed. */
   float *factor;
+  char *occluded;
 } AutomaskingCache;
 
 typedef struct FilterCache {
@@ -909,6 +910,8 @@ float SCULPT_vertex_mask_get(struct SculptSession *ss, int index);
 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]);
 
+bool SCULPT_vertex_is_occluded(SculptSession *ss, int vertex, bool original);
+
 /** Returns true if a color attribute exists in the current sculpt session. */
 bool SCULPT_has_colors(const SculptSession *ss);
 
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index e4bf0db5257..4a8aed41172 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -320,7 +320,7 @@ typedef enum eAutomasking_flag {
   BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS = (1 << 3),
   BRUSH_AUTOMASKING_BRUSH_NORMAL = (1 << 8),
   BRUSH_AUTOMASKING_VIEW_NORMAL = (1 << 9),
-
+  BRUSH_AUTOMASKING_VIEW_OCCLUSION = (1 << 10),
 } eAutomasking_flag;
 
 typedef enum ePaintBrush_flag {
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 279f0b234a9..cc288046dd8 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -3185,6 +3185,12 @@ static void rna_def_brush(BlenderRNA *brna)
                            "Mask back facing vertices");
   RNA_def_property_update(prop, 0, "rna_Brush_update");
   
+  prop = RNA_def_property(srna, "use_automasking_view_occlusion", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "automasking_flags", BRUSH_AUTOMASKING_VIEW_OCCLUSION);
+  RNA_def_property_ui_text(prop, "Occlusion", "Mask occluded vertices");
+  RNA_def_property_update(prop, 0, "rna_Brush_update");
+
+
   prop = RNA_def_property(srna, "use_scene_spacing", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
   RNA_def_property_enum_items(prop, brush_spacing_unit_items);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index b599c7bb449..0ce21aaae7e 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -917,6 +917,11 @@ static void rna_def_sculpt(BlenderRNA *brna)
                            "Mask back facing vertices");
   RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
 
+  prop = RNA_def_property(srna, "use_automasking_view_occlusion", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "automasking_flags", BRUSH_AUTOMASKING_VIEW_OCCLUSION);
+  RNA_def_property_ui_text(prop, "Occlusion", "Mask occluded vertices");
+  RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+
   prop = RNA_def_property(srna, "automasking_start_normal_limit", PROP_FLOAT, PROP_ANGLE);
   RNA_def_property_float_sdna(
       prop, NULL, "automasking_start_normal_limit");



More information about the Bf-blender-cvs mailing list