Vertex Paint: remove accumulate (soc-2017-vertex_paint)
authorCampbell Barton <ideasman42@gmail.com>
Tue, 3 Oct 2017 07:50:34 +0000 (18:50 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 3 Oct 2017 08:09:28 +0000 (19:09 +1100)
This secondary accumulation option accumulated brush falloff.
The same option in image painting accumulates color
as vertex paiht 'Spray' does.

Giving this option different behavior for vertex paint seems strange.
Also this is basically increasing falloff over time.

Remove the new code, expose existing 'Spray' as 'Accumulate'
to match other paint modes.

release/scripts/startup/bl_ui/space_view3d_toolbar.py
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/paint.c
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_sculpt_paint.c

index 798b5e28d9c83150081f55bf87b73d231d382f09..5aca4c554d865221a8d501abb06697efbd6f655b 100644 (file)
@@ -1773,7 +1773,6 @@ class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel):
         sub.prop(wpaint, "normal_angle", text="")
         col = layout.column()
         row = col.row()
-        row.prop(wpaint, "use_spray")
         row.prop(wpaint, "use_group_restrict")
 
         obj = context.weight_paint_object
@@ -1816,8 +1815,6 @@ class VIEW3D_PT_tools_vertexpaint(Panel, View3DPaintPanel):
         sub.active = (vpaint.use_normal_falloff)
         sub.prop(vpaint, "normal_angle", text="")
 
-        col.prop(vpaint, "use_spray")
-
         self.unified_paint_settings(col, context)
 
 
index 19f332f5f54b17e7e5a286b5f032a7377ed45b93..3a70819ec5818290f51495a78c042e40773b2db8 100644 (file)
@@ -220,18 +220,14 @@ typedef struct SculptSession {
 
                        /* For non-airbrush painting to re-apply from the original (MLoop aligned). */
                        unsigned int *previous_color;
-                       float        *previous_accum;
                } vpaint;
 
                struct {
                        struct SculptVertexPaintGeomMap gmap;
-
-                       /* Vertex aligned arrays of weights. */
-                       float *previous_accum;
                        /* Keep track of how much each vertex has been painted (non-airbrush only). */
                        float *alpha_weight;
 
-                       /* Needed to continuously re-apply over the same weights (VP_FLAG_SPRAY disabled).
+                       /* Needed to continuously re-apply over the same weights (BRUSH_ACCUMULATE disabled).
                         * Lazy initialize as needed (flag is set to 1 to tag it as uninitialized). */
                        struct MDeformVert *dvert_prev;
                } wpaint;
index c2f1d05dd8982c6a256743dc9cd96f44b9543e84..62af61585c156a834be61a0bfa83610f04f0a1de 100644 (file)
@@ -681,13 +681,11 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss)
                gmap = &ss->mode.vpaint.gmap;
 
                MEM_SAFE_FREE(ss->mode.vpaint.previous_color);
-               MEM_SAFE_FREE(ss->mode.vpaint.previous_accum);
        }
        else if (ss->mode_type == OB_MODE_WEIGHT_PAINT) {
                gmap = &ss->mode.wpaint.gmap;
 
                MEM_SAFE_FREE(ss->mode.wpaint.alpha_weight);
-               MEM_SAFE_FREE(ss->mode.wpaint.previous_accum);
                if (ss->mode.wpaint.dvert_prev) {
                        BKE_defvert_array_free_elems(ss->mode.wpaint.dvert_prev, ss->totvert);
                        MEM_freeN(ss->mode.wpaint.dvert_prev);
index d40dbd542dd798b13636631509ae547c7c1b5927..e1a4137d06959c1a3bfa04c54e59bc7c939314aa 100644 (file)
@@ -1690,7 +1690,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                                        VPaint *vp = i ? ts->vpaint : ts->wpaint;
                                        if (vp != NULL) {
                                                /* remove all other flags */
-                                               vp->flag &= (VP_FLAG_SPRAY | VP_FLAG_VGROUP_RESTRICT);
+                                               vp->flag &= (VP_FLAG_VGROUP_RESTRICT);
                                                vp->normal_angle = 80;
                                        }
                                }
index c61d250446ccc3ceab61c697323665b166c5c6db..ee8934422bc3027676799cfca7f8761a01c07a28 100644 (file)
@@ -241,11 +241,10 @@ int weight_paint_poll(bContext *C)
        return 0;
 }
 
-static VPaint *new_vpaint(int wpaint)
+static VPaint *new_vpaint(void)
 {
        VPaint *vp = MEM_callocN(sizeof(VPaint), "VPaint");
 
-       vp->flag = (wpaint) ? 0 : VP_FLAG_SPRAY;
        vp->paint.flags |= PAINT_SHOW_BRUSH;
 
        return vp;
@@ -272,8 +271,8 @@ static uint vpaint_blend(
 
        uint color_blend = ED_vpaint_blend_tool(tool, color_curr, color_paint, alpha_i);
 
-       /* if no spray, clip color adding with colorig & orig alpha */
-       if ((vp->flag & VP_FLAG_SPRAY) == 0) {
+       /* if no accumulate, clip color adding with colorig & orig alpha */
+       if ((brush->flag & BRUSH_ACCUMULATE) == 0) {
                uint color_test, a;
                char *cp, *ct, *co;
 
@@ -730,7 +729,7 @@ static void do_weight_paint_vertex_single(
                index_mirr = vgroup_mirr = -1;
        }
 
-       if ((wp->flag & VP_FLAG_SPRAY) == 0) {
+       if ((wp->paint.brush->flag & BRUSH_ACCUMULATE) == 0) {
                struct MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
                defweight_prev_restore_or_init(dvert_prev, me->dvert, index);
                if (index_mirr != -1) {
@@ -874,7 +873,7 @@ static void do_weight_paint_vertex_multi(
                }
        }
 
-       if ((wp->flag & VP_FLAG_SPRAY) == 0) {
+       if ((wp->paint.brush->flag & BRUSH_ACCUMULATE) == 0) {
                struct MDeformVert *dvert_prev = ob->sculpt->mode.wpaint.dvert_prev;
                defweight_prev_restore_or_init(dvert_prev, me->dvert, index);
                if (index_mirr != -1) {
@@ -1007,7 +1006,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
 
        /* Create average brush arrays */
        if (ob->mode == OB_MODE_VERTEX_PAINT) {
-               if ((ts->vpaint->flag & VP_FLAG_SPRAY) == 0) {
+               if ((brush->flag & BRUSH_ACCUMULATE) == 0) {
                        if (ob->sculpt->mode.vpaint.previous_color == NULL) {
                                ob->sculpt->mode.vpaint.previous_color =
                                        MEM_callocN(me->totloop * sizeof(uint), __func__);
@@ -1016,19 +1015,9 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
                else {
                        MEM_SAFE_FREE(ob->sculpt->mode.vpaint.previous_color);
                }
-
-               if (brush && brush->flag & BRUSH_ACCUMULATE) {
-                       if (ob->sculpt->mode.vpaint.previous_accum == NULL) {
-                               ob->sculpt->mode.vpaint.previous_accum =
-                                       MEM_callocN(me->totloop * sizeof(float), __func__);
-                       }
-               }
-               else {
-                       MEM_SAFE_FREE(ob->sculpt->mode.vpaint.previous_accum);
-               }
        }
        else if (ob->mode == OB_MODE_WEIGHT_PAINT) {
-               if ((ts->wpaint->flag & VP_FLAG_SPRAY) == 0) {
+               if ((brush->flag & BRUSH_ACCUMULATE) == 0) {
                        if (ob->sculpt->mode.wpaint.alpha_weight == NULL) {
                                ob->sculpt->mode.wpaint.alpha_weight =
                                        MEM_callocN(me->totvert * sizeof(float), __func__);
@@ -1051,15 +1040,6 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
                                ob->sculpt->mode.wpaint.dvert_prev = NULL;
                        }
                }
-               if (brush && brush->flag & BRUSH_ACCUMULATE) {
-                       if (ob->sculpt->mode.wpaint.previous_accum == NULL) {
-                               ob->sculpt->mode.wpaint.previous_accum =
-                                       MEM_callocN(me->totvert * sizeof(float), __func__);
-                       }
-               }
-               else {
-                       MEM_SAFE_FREE(ob->sculpt->mode.wpaint.previous_accum);
-               }
        }
 
 }
@@ -1114,7 +1094,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
                ob->mode |= mode_flag;
 
                if (wp == NULL)
-                       wp = scene->toolsettings->wpaint = new_vpaint(1);
+                       wp = scene->toolsettings->wpaint = new_vpaint();
 
                paint_cursor_start(C, weight_paint_poll);
 
@@ -1557,14 +1537,17 @@ static void do_wpaint_brush_blur_task_cb_ex(
                                             view_angle_limits_apply_falloff(&data->wpd->normal_angle_precalc, angle_cos, &brush_strength)))
                                        {
                                                const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
-                                               float final_alpha =
+                                               const float final_alpha =
                                                        brush_fade * brush_strength *
                                                        grid_alpha * brush_alpha_pressure;
 
-                                               if (brush->flag & BRUSH_ACCUMULATE) {
-                                                       float mask_accum = ss->mode.wpaint.previous_accum[v_index];
-                                                       final_alpha = min_ff(final_alpha + mask_accum, brush_strength);
-                                                       ss->mode.wpaint.previous_accum[v_index] = final_alpha;
+                                               if ((brush->flag & BRUSH_ACCUMULATE) == 0) {
+                                                       if (ss->mode.wpaint.alpha_weight[v_index] < final_alpha) {
+                                                               ss->mode.wpaint.alpha_weight[v_index] = final_alpha;
+                                                       }
+                                                       else {
+                                                               continue;
+                                                       }
                                                }
 
                                                weight_final /= total_hit_loops;
@@ -1729,16 +1712,9 @@ static void do_wpaint_brush_draw_task_cb_ex(
                                     view_angle_limits_apply_falloff(&data->wpd->normal_angle_precalc, angle_cos, &brush_strength)))
                                {
                                        const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
-                                       float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure;
-                                       if (brush->flag & BRUSH_ACCUMULATE) {
-                                               float mask_accum = ss->mode.wpaint.previous_accum[v_index];
-                                               final_alpha = min_ff(final_alpha + mask_accum, brush_strength);
-                                               ss->mode.wpaint.previous_accum[v_index] = final_alpha;
-                                       }
+                                       const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure;
 
-                                       /* Non-spray logic. */
-                                       if ((data->vp->flag & VP_FLAG_SPRAY) == 0) {
-                                               /* Only paint if we have greater alpha. */
+                                       if ((brush->flag & BRUSH_ACCUMULATE) == 0) {
                                                if (ss->mode.wpaint.alpha_weight[v_index] < final_alpha) {
                                                        ss->mode.wpaint.alpha_weight[v_index] = final_alpha;
                                                }
@@ -1804,9 +1780,6 @@ static void do_wpaint_brush_calc_average_weight_cb_ex(
 
 static void calculate_average_weight(SculptThreadedTaskData *data, PBVHNode **UNUSED(nodes), int totnode)
 {
-       Scene *scene = CTX_data_scene(data->C);
-       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
-
        struct WPaintAverageAccum *accum = MEM_mallocN(sizeof(*accum) * totnode, __func__);
        data->custom_data = accum;
 
@@ -2236,7 +2209,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
                ED_mesh_color_ensure(me, NULL);
 
                if (vp == NULL)
-                       vp = scene->toolsettings->vpaint = new_vpaint(0);
+                       vp = scene->toolsettings->vpaint = new_vpaint();
 
                paint_cursor_start(C, vertex_paint_poll);
 
@@ -2538,14 +2511,9 @@ static void do_vpaint_brush_draw_task_cb_ex(
                                                                }
                                                                color_orig = ss->mode.vpaint.previous_color[l_index];
                                                        }
-                                                       float final_alpha =
+                                                       const float final_alpha =
                                                                255 * brush_fade * brush_strength *
                                                                tex_alpha * brush_alpha_pressure * grid_alpha;
-                                                       if (brush->flag & BRUSH_ACCUMULATE) {
-                                                               float mask_accum = ss->mode.vpaint.previous_accum[l_index];
-                                                               final_alpha = min_ff(final_alpha + mask_accum, 255.0f * brush_strength);
-                                                               ss->mode.vpaint.previous_accum[l_index] = final_alpha;
-                                                       }
 
                                                        /* Mix the new color with the original based on final_alpha. */
                                                        lcol[l_index] = vpaint_blend(
@@ -2649,7 +2617,7 @@ static void do_vpaint_brush_blur_task_cb_ex(
                                                                        }
                                                                        color_orig = ss->mode.vpaint.previous_color[l_index];
                                                                }
-                                                               float final_alpha =
+                                                               const float final_alpha =
                                                                        255 * brush_fade * brush_strength *
                                                                        brush_alpha_pressure * grid_alpha;
                                                                /* Mix the new color with the original
@@ -2777,7 +2745,7 @@ static void do_vpaint_brush_smear_task_cb_ex(
                                                                                }
                                                                                color_orig = ss->mode.vpaint.previous_color[l_index];
                                                                        }
-                                                                       float final_alpha =
+                                                                       const float final_alpha =
                                                                                255 * brush_fade * brush_strength *
                                                                                brush_alpha_pressure * grid_alpha;
                                                                        /* Mix the new color with the original
index e9caf7ada1c1d0d9c2d2826bf716dc5ce904968f..89a8a410f3ea61e87f3843bd6cacce756c3d927a 100644 (file)
@@ -1128,7 +1128,6 @@ enum {
        /* TODO */
        // VP_FLAG_PROJECT_XRAY        = (1 << 1),
        VP_FLAG_PROJECT_FLAT        = (1 << 3),
-       VP_FLAG_SPRAY               = (1 << 4),
        /* weight paint only */
        VP_FLAG_VGROUP_RESTRICT     = (1 << 7)
 };
index 6c89767ad29f42afdfe031df4f0f78815e081893..6e493e2c86564d7723a47e70b37963dfcbe7e24d 100644 (file)
@@ -692,12 +692,6 @@ static void rna_def_vertex_paint(BlenderRNA *brna)
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", VP_FLAG_PROJECT_FLAT);
        RNA_def_property_ui_text(prop, "Normals", "Paint most on faces pointing towards the view");
        RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
-       
-
-       prop = RNA_def_property(srna, "use_spray", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", VP_FLAG_SPRAY);
-       RNA_def_property_ui_text(prop, "Spray", "Keep applying paint effect while holding mouse");
-       RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
 
        /* weight paint only */
        prop = RNA_def_property(srna, "use_group_restrict", PROP_BOOLEAN, PROP_NONE);