[Bf-blender-cvs] [320ff879485] sculpt-dev: Sculpt: Quantize mask filter

Pablo noreply at git.blender.org
Sat Aug 28 19:58:26 CEST 2021


Commit: 320ff879485213d4bb3eda2e40f7481cc6d7c83c
Author: Pablo
Date:   Sat Aug 28 19:57:32 2021 +0200
Branches: sculpt-dev
https://developer.blender.org/rB320ff879485213d4bb3eda2e40f7481cc6d7c83c

Sculpt: Quantize mask filter

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

M	source/blender/editors/sculpt_paint/sculpt_filter_mask.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
index 1dc6886f699..97b960ff9e4 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
@@ -322,6 +322,8 @@ void SCULPT_OT_mask_filter(struct wmOperatorType *ot)
 #define SCULPT_IPMASK_FILTER_MIN_MULTITHREAD 1000
 #define SCULPT_IPMASK_FILTER_GRANULARITY 100
 
+#define SCULPT_IPMASK_FILTER_QUANTIZE_STEP 0.1
+
 typedef enum eSculptIPMaskFilterType {
   IPMASK_FILTER_SMOOTH_SHARPEN,
   IPMASK_FILTER_GROW_SHRINK,
@@ -329,6 +331,7 @@ typedef enum eSculptIPMaskFilterType {
   IPMASK_FILTER_CONTRAST,
   IPMASK_FILTER_ADD_SUBSTRACT,
   IPMASK_FILTER_INVERT,
+  IPMASK_FILTER_QUANTIZE,
 } eSculptIPMaskFilterType;
 
 typedef enum MaskFilterStepDirectionType {
@@ -791,6 +794,14 @@ static void ipmask_filter_apply_from_original_task_cb(
   SculptOrigVertData orig_data;
   const eSculptIPMaskFilterType filter_type = data->filter_type;
   bool update = false;
+
+  /* Used for quantize filter. */
+  const int steps = data->filter_strength / SCULPT_IPMASK_FILTER_QUANTIZE_STEP;
+  if (steps == 0) {
+    return;
+  }
+  const float step_size = 1.0f/steps;
+
   SCULPT_orig_vert_data_init(&orig_data, data->ob, node);
   BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) {
     if (SCULPT_automasking_factor_get(filter_cache->automasking, ss, vd.index) < 0.5f) {
@@ -808,6 +819,12 @@ static void ipmask_filter_apply_from_original_task_cb(
         new_mask = interpf(mask_invert, orig_data.mask, strength);
         break;
       }
+      case IPMASK_FILTER_QUANTIZE: {
+        const float remainder = fmod(orig_data.mask, step_size);
+        const float total_steps = (orig_data.mask - remainder) / step_size;
+        new_mask = total_steps * step_size;
+        break;
+      }
       default:
         BLI_assert(false);
         break;
@@ -853,7 +870,7 @@ static void sculpt_ipmask_apply_from_original_mask_data(Object *ob,
 static bool sculpt_ipmask_filter_uses_apply_from_original(
     const eSculptIPMaskFilterType filter_type)
 {
-  return ELEM(filter_type, IPMASK_FILTER_INVERT, IPMASK_FILTER_ADD_SUBSTRACT);
+  return ELEM(filter_type, IPMASK_FILTER_INVERT, IPMASK_FILTER_ADD_SUBSTRACT, IPMASK_FILTER_QUANTIZE);
 }
 
 static void ipmask_filter_restore_original_mask_task_cb(
@@ -1099,6 +1116,7 @@ void SCULPT_OT_ipmask_filter(struct wmOperatorType *ot)
        "Contrast",
        "Increases or decreases the contrast of the mask"},
       {IPMASK_FILTER_INVERT, "INVERT", 0, "Invert", "Inverts the mask"},
+      {IPMASK_FILTER_QUANTIZE, "QUANTIZE", 0, "Quantize", "Quantizes the mask to intervals"},
       {0, NULL, 0, NULL, NULL},
   };



More information about the Bf-blender-cvs mailing list