[Bf-blender-cvs] [6948d7973b1] temp-pbvh-texpaint-automasking: Merge branch 'master' into temp-pbvh-texpaint-automasking

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


Commit: 6948d7973b1fb5765a4420bfd0fd171714937f52
Author: Joseph Eagar
Date:   Tue Oct 11 11:07:02 2022 -0700
Branches: temp-pbvh-texpaint-automasking
https://developer.blender.org/rB6948d7973b1fb5765a4420bfd0fd171714937f52

Merge branch 'master' into temp-pbvh-texpaint-automasking

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



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

diff --cc source/blender/blenkernel/BKE_pbvh.h
index 380820030b1,89743f1d2b4..e314d9263bd
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@@ -79,8 -125,8 +125,8 @@@ typedef enum 
    PBVH_UpdateTopology = 1 << 13,
    PBVH_UpdateColor = 1 << 14,
    PBVH_RebuildPixels = 1 << 15,
-   PBVH_RebuildAutomasking = 1 << 16,
- 
+   PBVH_TopologyUpdated = 1 << 16, /* Used internally by pbvh_bmesh.c */
 -
++  PBVH_RebuildAutomasking = 1 << 17,
  } PBVHNodeFlags;
  
  typedef struct PBVHFrustumPlanes {
@@@ -414,7 -559,8 +559,9 @@@ typedef struct PBVHVertexIter 
    /* mesh */
    struct MVert *mverts;
    float (*vert_normals)[3];
++
+   const bool *hide_vert;
 -  int totvert;
 +  int totvert, unique_verts;
    const int *vert_indices;
    float *vmask;
  
@@@ -587,24 -740,8 +741,25 @@@ void BKE_pbvh_vertex_color_get(const PB
  
  void BKE_pbvh_ensure_node_loops(PBVH *pbvh);
  bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh);
+ int BKE_pbvh_debug_draw_gen_get(PBVHNode *node);
  
 +void BKE_pbvh_node_automasking_mark(PBVH *pbvh, PBVHNode *node);
 +void BKE_pbvh_node_automasking_unmark(PBVH *pbvh, PBVHNode *node);
 +bool BKE_pbvh_node_needs_automasking(PBVH *pbvh, PBVHNode *node);
 +void BKE_pbvh_node_automasking_mark_all(PBVH *pbvh);
 +
 +/* XXX Temporary attribute for patch development; remove for final patch! */
 +#ifdef __clang__
 +#  define ATTR_NO_OPT __attribute__((optnone))
 +#elif defined(_MSC_VER)
 +#  define ATTR_NO_OPT __pragma(optimize("", off))
 +#elif defined(__GNUC__)
 +#  define ATTR_NO_OPT __attribute__((optimize("O0")))
 +#else
 +#  define ATTR_NO_OPT
 +#endif
 +
 +
  #ifdef __cplusplus
  }
  #endif
diff --cc source/blender/blenkernel/intern/pbvh.c
index 68d1e519469,b23fe53e80c..f2b74f67506
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@@ -3324,26 -3308,7 +3311,31 @@@ void BKE_pbvh_ensure_node_loops(PBVH *p
    MEM_SAFE_FREE(visit);
  }
  
 +void BKE_pbvh_node_automasking_mark(PBVH *pbvh, PBVHNode *node)
 +{
 +  node->flag |= PBVH_RebuildAutomasking;
 +}
 +
 +void BKE_pbvh_node_automasking_unmark(PBVH *pbvh, PBVHNode *node)
 +{
 +  node->flag &= ~PBVH_RebuildAutomasking;
 +}
 +
 +bool BKE_pbvh_node_needs_automasking(PBVH *pbvh, PBVHNode *node)
 +{
 +  return node->flag & PBVH_RebuildAutomasking;
 +}
 +
 +void BKE_pbvh_node_automasking_mark_all(PBVH *pbvh)
 +{
 +  for (int i = 0; i < pbvh->totnode; i++) {
 +    if (pbvh->nodes[i].flag & PBVH_Leaf) {
 +      pbvh->nodes[i].flag |= PBVH_RebuildAutomasking;
 +    }
 +  }
 +}
++
+ int BKE_pbvh_debug_draw_gen_get(PBVHNode *node)
+ {
+   return node->debug_draw_gen;
+ }
diff --cc source/blender/editors/sculpt_paint/sculpt.c
index b58e385ddb3,129bb604ed0..c5b977dcb5f
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@@ -5335,21 -5482,11 +5484,16 @@@ static bool sculpt_stroke_test_start(bC
      SculptCursorGeometryInfo sgi;
      SCULPT_cursor_geometry_info_update(C, &sgi, mval, false);
  
-     /* Setup the correct undo system. Image painting and sculpting are mutual exclusive.
-      * Color attributes are part of the sculpting undo system. */
-     if (brush && brush->sculpt_tool == SCULPT_TOOL_PAINT &&
-         SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
-       ED_image_undo_push_begin(op->type->name, PAINT_MODE_SCULPT);
-     }
-     else {
-       SCULPT_undo_push_begin(ob, sculpt_tool_name(sd));
-     }
+     sculpt_stroke_undo_begin(C, op);
+ 
+     SCULPT_stroke_id_next(ob);
+     ss->cache->stroke_id = ss->stroke_id;
  
 +    /* Mark all pbvh nodes for update. */
 +    if (ss->pbvh) {
 +      BKE_pbvh_node_automasking_mark_all(ss->pbvh);
 +    }
 +
      return true;
    }
    return false;
diff --cc source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 4d40f473fd3,505440c9272..0b434d16797
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@@ -11,9 -12,9 +12,10 @@@
  #include "BLI_hash.h"
  #include "BLI_index_range.hh"
  #include "BLI_math.h"
+ #include "BLI_math_vec_types.hh"
  #include "BLI_set.hh"
  #include "BLI_task.h"
 +#include "BLI_task.hh"
  #include "BLI_vector.hh"
  
  #include "DNA_brush_types.h"
@@@ -119,8 -193,345 +194,351 @@@ static bool SCULPT_automasking_needs_fa
    return false;
  }
  
- float sculpt_automasking_factor_calc(AutomaskingCache *automasking, SculptSession *ss, int vert)
+ static float automasking_brush_normal_factor(AutomaskingCache *automasking,
+                                              SculptSession *ss,
+                                              PBVHVertRef vertex,
+                                              AutomaskingNodeData *automask_data)
+ {
+   float falloff = automasking->settings.start_normal_falloff * M_PI;
+   float3 initial_normal;
+ 
+   if (ss->cache) {
+     initial_normal = ss->cache->initial_normal;
+   }
+   else {
+     initial_normal = ss->filter_cache->initial_normal;
+   }
+ 
+   return sculpt_automasking_normal_calc(ss,
+                                         vertex,
+                                         initial_normal,
+                                         automasking->settings.start_normal_limit - falloff * 0.5f,
+                                         automasking->settings.start_normal_limit + falloff * 0.5f,
+                                         automask_data);
+ }
+ 
+ static float automasking_view_normal_factor(AutomaskingCache *automasking,
+                                             SculptSession *ss,
+                                             PBVHVertRef vertex,
+                                             AutomaskingNodeData *automask_data)
+ {
+   float falloff = automasking->settings.view_normal_falloff * M_PI;
+ 
+   float3 view_normal;
+ 
+   if (ss->cache) {
+     view_normal = ss->cache->view_normal;
+   }
+   else {
+     view_normal = ss->filter_cache->view_normal;
+   }
+ 
+   return sculpt_automasking_normal_calc(ss,
+                                         vertex,
+                                         view_normal,
+                                         automasking->settings.view_normal_limit,
+                                         automasking->settings.view_normal_limit + falloff,
+                                         automask_data);
+ }
+ 
+ static float automasking_view_occlusion_factor(AutomaskingCache *automasking,
+                                                SculptSession *ss,
+                                                PBVHVertRef vertex,
+                                                uchar stroke_id,
+                                                AutomaskingNodeData * /*automask_data*/)
+ {
+   char f = *(char *)SCULPT_vertex_attr_get(vertex, ss->attrs.automasking_occlusion);
+ 
+   if (stroke_id != automasking->current_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,
+                                     AutomaskingCache *automasking,
+                                     PBVHVertRef vertex,
+                                     float value)
+ {
+   if (ss->attrs.automasking_stroke_id) {
+     *(uchar *)SCULPT_vertex_attr_get(
+         vertex, ss->attrs.automasking_stroke_id) = automasking->current_stroke_id;
+   }
+ 
+   return value;
+ }
+ 
+ static float sculpt_cavity_calc_factor(AutomaskingCache *automasking, float factor)
+ {
+   float sign = signf(factor);
+ 
+   factor = fabsf(factor) * automasking->settings.cavity_factor * 50.0f;
+ 
+   factor = factor * sign * 0.5f + 0.5f;
+   CLAMP(factor, 0.0f, 1.0f);
+ 
+   return (automasking->settings.flags & BRUSH_AUTOMASKING_CAVITY_INVERTED) ? 1.0f - factor :
+                                                                              factor;
+ }
+ 
+ struct CavityBlurVert {
+   PBVHVertRef vertex;
+   float dist;
+   int depth;
+ 
+   CavityBlurVert(PBVHVertRef vertex_, float dist_, int depth_)
+       : vertex(vertex_), dist(dist_), depth(depth_)
+   {
+   }
+ 
+   CavityBlurVert() = default;
+ };
+ 
+ static void sculpt_calc_blurred_cavity(SculptSession *ss,
+                                        AutomaskingCache *automasking,
+                                        int steps,
+                                        PBVHVertRef vertex)
+ {
+   float3 sno1(0.0f);
+   float3 sno2(0.0f);
+   float3 sco1(0.0f);
+   float3 sco2(0.0f);
+   float len1_sum = 0.0f;
+   int sco1_len = 0, sco2_len = 0;
+ 
+   /* Steps starts at 1, but API and user interface
+    * are zero-based.
+    */
+   steps++;
+ 
+   Vector<CavityBlurVert, 64> queue;
+   Set<int64_t, 64> visit;
+ 
+   int start = 0, end = 0;
+ 
+   queue.resize(64);
+ 
+   CavityBlurVert initial(vertex, 0.0f, 0);
+ 
+   visit.add_new(vertex.i);
+   queue[0] = initial;
+   end = 1;
+ 
+   const float *co1 = SCULPT_vertex_co_get(ss, vertex);
+ 
+   while (start != end) {
+     CavityBlurVert &blurvert = queue[start];
+     PBVHVertRef v = blurvert.vertex;
+     start = (start + 1) % queue.size();
+ 
+     float3 no;
+ 
+     const float *co = SCULPT_vertex_co_get(ss, v);
+     SCULPT_vertex_normal_get(ss, v, no);
+ 
+     float centdist = len_v3v3(co, co1);
+ 
+     sco1 += co;
+     sno1 += no;
+     len1_sum += centdist;
+     sco1_len++;
+ 
+     if (blurvert.depth < steps) {
+       sco2 += co;
+       sno2 += no;
+       sco2_len++;
+     }
+ 
+     if (blurvert.depth >= steps) {
+       continue;
+     }
+ 
+     SculptVertexNeighborIter ni;
+     SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, v, ni) {
+       PBVHVertRef v2 = ni.vertex;
+ 
+       if (visit.contains(v2.i)) {
+         continue;
+       }
+ 
+       float dist = len_v3v3(SCULPT_vertex_co_get(ss, v2), SCULPT_vertex_co_get(ss, v));
+ 
+       visit.add_new(v2.i);
+       CavityBlurVert blurvert2(v2, dist, blurvert.depth + 1);
+ 
+       int nextend = (end + 1) % queue.size();
+ 
+       if (nextend == start) {
+         int oldsize = queue.size();
+ 
+         queue.resize(queue.siz

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list