[Bf-blender-cvs] [098d0d782ad] sculpt-dev: Sculp IPMask: First working version of substep interpolation
Pablo Dobarro
noreply at git.blender.org
Mon Mar 1 22:16:00 CET 2021
Commit: 098d0d782adb60fce7c13cd31af5d79218670241
Author: Pablo Dobarro
Date: Mon Mar 1 19:19:41 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB098d0d782adb60fce7c13cd31af5d79218670241
Sculp IPMask: First working version of substep interpolation
===================================================================
M source/blender/editors/sculpt_paint/sculpt_filter_mask.c
M source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
index 9f4b14959bb..ff689c4156d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_mask.c
@@ -542,14 +542,27 @@ static float *sculpt_ipmask_step_compute(SculptSession *ss,
static float *sculpt_ipmask_current_state_get(SculptSession *ss)
{
- const int totvert = SCULPT_vertex_count_get(ss);
- float *current_mask = MEM_malloc_arrayN(sizeof(float), totvert, "delta values");
+ return MEM_dupallocN(ss->filter_cache->mask_filter_ref);
+}
+static void sculpt_ipmask_reference_set(SculptSession *ss, float *new_mask)
+{
+ const int totvert = SCULPT_vertex_count_get(ss);
for (int i = 0; i < totvert; i++) {
- current_mask[i] = SCULPT_vertex_mask_get(ss, i);
+ ss->filter_cache->mask_filter_ref[i] = new_mask[i];
}
+}
- return current_mask;
+static void sculpt_ipmask_store_reference_step(SculptSession *ss)
+{
+ const int totvert = SCULPT_vertex_count_get(ss);
+ if (!ss->filter_cache->mask_filter_ref) {
+ ss->filter_cache->mask_filter_ref = MEM_malloc_arrayN(sizeof(float), totvert, "delta values");
+ }
+
+ for (int i = 0; i < totvert; i++) {
+ ss->filter_cache->mask_filter_ref[i] = SCULPT_vertex_mask_get(ss, i);
+ }
}
static void ipmask_filter_apply_task_cb(void *__restrict userdata,
@@ -568,10 +581,19 @@ static void ipmask_filter_apply_task_cb(void *__restrict userdata,
continue;
}
- if (*vd.mask == data->new_mask[vd.index]) {
+ float new_mask;
+ if (data->next_mask) {
+ new_mask = interpf(data->next_mask[vd.index], data->new_mask[vd.index], data->mask_interpolation);
+ }
+ else {
+ new_mask = data->new_mask[vd.index];
+ }
+
+ if (*vd.mask == new_mask) {
continue;
}
- *vd.mask = data->new_mask[vd.index];
+
+ *vd.mask = new_mask;
update = true;
if (vd.mvert) {
vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
@@ -584,13 +606,15 @@ static void ipmask_filter_apply_task_cb(void *__restrict userdata,
}
}
-static void sculpt_ipmask_apply_mask_data(SculptSession *ss, float *new_mask)
+static void sculpt_ipmask_apply_mask_data(SculptSession *ss, float *new_mask, float *next_mask, const float interpolation)
{
FilterCache *filter_cache = ss->filter_cache;
SculptThreadedTaskData data = {
.ss = ss,
.nodes = filter_cache->nodes,
.new_mask = new_mask,
+ .next_mask = next_mask,
+ .mask_interpolation = interpolation,
};
TaskParallelSettings settings;
@@ -699,8 +723,8 @@ static void sculpt_ipmask_filter_update_to_target_step(SculptSession *ss, const
/* Restore or compute a mask in the given direction. */
float *new_mask = sculpt_ipmask_filter_mask_for_step_get(ss, direction, iteration_count);
- /* Apply the mask data to the mesh. */
- sculpt_ipmask_apply_mask_data(ss, new_mask);
+ /* Store the full step. */
+ sculpt_ipmask_reference_set(ss, new_mask);
MEM_freeN(new_mask);
/* Update the current step count. */
@@ -713,8 +737,12 @@ static void sculpt_ipmask_filter_update_to_target_step(SculptSession *ss, const
}
if (step_interpolation != 0.0f) {
-
-
+ float *next_mask = sculpt_ipmask_filter_mask_for_step_get(ss, MASK_FILTER_STEP_DIRECTION_FORWARD, iteration_count);
+ sculpt_ipmask_apply_mask_data(ss, filter_cache->mask_filter_ref, next_mask, step_interpolation);
+ MEM_freeN(next_mask);
+ }
+ else {
+ sculpt_ipmask_apply_mask_data(ss, filter_cache->mask_filter_ref, NULL, 0.0f);
}
}
@@ -723,7 +751,7 @@ bool sculpt_ipmask_filter_apply_from_original(const eSculptIPMaskFilterType filt
return true;
}
-#define IPMASK_FILTER_STEP_SENSITIVITY 0.05f
+#define IPMASK_FILTER_STEP_SENSITIVITY 0.008f
static int sculpt_ipmask_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = CTX_data_active_object(C);
@@ -748,8 +776,10 @@ static int sculpt_ipmask_filter_modal(bContext *C, wmOperator *op, const wmEvent
}
const float len = event->x - event->prevclickx;
- const int target_step = len * IPMASK_FILTER_STEP_SENSITIVITY * UI_DPI_FAC;
- const float step_interpolation = 0.5f;
+ const float target_step_fl = len * IPMASK_FILTER_STEP_SENSITIVITY * UI_DPI_FAC;
+ const int target_step = floorf(target_step_fl);
+ const float step_interpolation = target_step_fl - target_step;
+ printf("STEP INTERPOLATION %f\n", step_interpolation);
BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false);
@@ -786,6 +816,8 @@ static int sculpt_ipmask_filter_invoke(bContext *C, wmOperator *op, const wmEven
filter_cache->mask_delta_step = BLI_ghash_int_new("mask filter delta steps");
+ sculpt_ipmask_store_reference_step(ss);
+
const int filter_type = RNA_enum_get(op->ptr, "filter_type");
switch (filter_type) {
case IPMASK_FILTER_SMOOTH_SHARPEN:
diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
index ca58732378f..915f0e57ccc 100644
--- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
+++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
@@ -192,6 +192,7 @@ void SCULPT_filter_cache_free(SculptSession *ss)
if (ss->filter_cache->mask_delta_step) {
BLI_ghash_free(ss->filter_cache->mask_delta_step, NULL, mask_filter_delta_step_free);
}
+ MEM_SAFE_FREE(ss->filter_cache->mask_filter_ref);
MEM_SAFE_FREE(ss->filter_cache->nodes);
MEM_SAFE_FREE(ss->filter_cache->mask_update_it);
MEM_SAFE_FREE(ss->filter_cache->prev_mask);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 8b789fc12bc..4b2dfde22eb 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -753,6 +753,8 @@ typedef struct SculptThreadedTaskData {
float *prev_mask;
float *new_mask;
+ float *next_mask;
+ float mask_interpolation;
float *pose_factor;
float *pose_initial_co;
@@ -1373,6 +1375,7 @@ typedef struct FilterCache {
/* Mask Filter. */
int mask_filter_current_step;
+ float *mask_filter_ref;
SculptIPMaskFilterStepVertexCB *mask_filter_step_forward;
SculptIPMaskFilterStepVertexCB *mask_filter_step_backward;
More information about the Bf-blender-cvs
mailing list