[Bf-blender-cvs] [344b2ab8bdf] soc-2016-pbvh-painting: Resolve bug w/ non-airbrush weight-paint blending
Campbell Barton
noreply at git.blender.org
Wed Sep 27 03:37:44 CEST 2017
Commit: 344b2ab8bdf31bd8e504eb033d629c11c167cd73
Author: Campbell Barton
Date: Wed Sep 27 11:46:39 2017 +1000
Branches: soc-2016-pbvh-painting
https://developer.blender.org/rB344b2ab8bdf31bd8e504eb033d629c11c167cd73
Resolve bug w/ non-airbrush weight-paint blending
Instead of clamping the max-weight (which locked the value at 1.0),
Store the initial weight and maximum strength used for painting.
Repaint only with a higher strength, using the initial weight.
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/paint.c
M source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 4ace75e3c4d..782f45e6cb9 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -216,7 +216,8 @@ typedef struct SculptSession {
unsigned int (*total_color)[3];
double *total_weight;
unsigned int *tot_loops_hit;
- float *max_weight;
+ float *alpha_weight;
+ float *previous_weight;
unsigned int *previous_color;
bool building_vp_handle;
} vwpaint;
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 39e8d0d4a26..a96e6158584 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -685,7 +685,8 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss)
MEM_SAFE_FREE(ss->modes.vwpaint.tot_loops_hit);
MEM_SAFE_FREE(ss->modes.vwpaint.total_color);
MEM_SAFE_FREE(ss->modes.vwpaint.total_weight);
- MEM_SAFE_FREE(ss->modes.vwpaint.max_weight);
+ MEM_SAFE_FREE(ss->modes.vwpaint.alpha_weight);
+ MEM_SAFE_FREE(ss->modes.vwpaint.previous_weight);
MEM_SAFE_FREE(ss->modes.vwpaint.previous_color);
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 2d45bc5504d..901086fa44f 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -83,6 +83,13 @@
#include "sculpt_intern.h"
#include "paint_intern.h" /* own include */
+static void defweight_prev_init(const MDeformWeight *dw, float *weight_prev)
+{
+ if (UNLIKELY(*weight_prev == -1.0f)) {
+ *weight_prev = dw ? dw->weight : 0.0f;
+ }
+}
+
/* check if we can do partial updates and have them draw realtime
* (without rebuilding the 'derivedFinal') */
static bool vertex_paint_use_fast_update_check(Object *ob)
@@ -1741,8 +1748,10 @@ static void vertex_paint_init_session_average_arrays(Object *ob)
MEM_callocN(totNode * sizeof(double), "total_weight");
ob->sculpt->modes.vwpaint.tot_loops_hit =
MEM_callocN(totNode * sizeof(uint), "tot_loops_hit");
- ob->sculpt->modes.vwpaint.max_weight =
- MEM_callocN(me->totvert * sizeof(float), "max_weight");
+ ob->sculpt->modes.vwpaint.alpha_weight =
+ MEM_callocN(me->totvert * sizeof(float), "alpha_weight");
+ ob->sculpt->modes.vwpaint.previous_weight =
+ MEM_callocN(me->totvert * sizeof(float), "previous_weight");
ob->sculpt->modes.vwpaint.previous_color =
MEM_callocN(me->totloop * sizeof(uint), "previous_color");
}
@@ -2209,8 +2218,10 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
vertex_paint_init_session_maps(ob);
vertex_paint_init_session_average_arrays(ob);
- for (int i = 0; i < me->totvert; i++)
- ss->modes.vwpaint.max_weight[i] = -1.0;
+ for (int i = 0; i < me->totvert; i++) {
+ ss->modes.vwpaint.alpha_weight[i] = 0.0f;
+ ss->modes.vwpaint.previous_weight[i] = -1.0f;
+ }
return true;
}
@@ -2569,22 +2580,23 @@ static void do_wpaint_brush_draw_task_cb_ex(
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
float final_alpha = view_dot * brush_fade * brush_strength * grid_alpha * brush_alpha_pressure;
- /* Spray logic */
+ /* Non-spray logic. */
if ((data->vp->flag & VP_SPRAY) == 0) {
- MDeformVert *dv = &data->me->dvert[v_index];
- const MDeformWeight *dw;
- dw = (data->vp->flag & VP_ONLYVGROUP) ?
- defvert_find_index(dv, data->wpi->active.index) :
- defvert_verify_index(dv, data->wpi->active.index);
- const float weight_curr = dw->weight;
- if (ss->modes.vwpaint.max_weight[v_index] < 0) {
- ss->modes.vwpaint.max_weight[v_index] = min_ff(brush_strength + weight_curr, 1.0f);
+ /* Only paint if we have greater alpha. */
+ if (ss->modes.vwpaint.alpha_weight[v_index] < final_alpha) {
+ ss->modes.vwpaint.alpha_weight[v_index] = final_alpha;
}
- CLAMP(final_alpha, 0.0, ss->modes.vwpaint.max_weight[v_index] - weight_curr);
-
- if (weight_curr >= ss->modes.vwpaint.max_weight[v_index]) {
+ else {
continue;
}
+
+ MDeformVert *dv = &data->me->dvert[v_index];
+ MDeformWeight *dw = defvert_find_index(dv, data->wpi->active.index);
+ float *weight_prev = &ss->modes.vwpaint.previous_weight[v_index];
+ defweight_prev_init(dw, weight_prev);
+ if (dw) {
+ dw->weight = *weight_prev;
+ }
}
do_weight_paint_vertex(
More information about the Bf-blender-cvs
mailing list