From d4f5d4a6f60445bdfc67c4fe559bdf7136fa4863 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Wed, 26 Jun 2024 15:38:26 +0200 Subject: [PATCH] Fix #123770: Vertex paint Accumulate option breaks Blur action Accumulating allocates previous colors (which are used in `do_vpaint_brush_blur_XXX`). The actual problem here was that the state of `brush_use_accumulate` was not consistent across the lifetime of strokes. Vertexpaint was doing the allocation in `vertex_paint_init_stroke` (**before** `update_cache_invariants` where the mode gets changed to `BRUSH_STROKE_SMOOTH` etc.), so here it still seemed we would use accumulation, whereas later (after internally switching the tool/brush) this was not the case anymore, leading to wrong behavior of `do_vpaint_brush_blur_XXX`. So now move the allocation to `init_session_data` (same as for weightpaint) to make sure all codepaths have a consistent state of `brush_use_accumulate`. NOTE: this was made more obvious since 6de6d7267f3d added SHIFT-blurring to the keymap Pull Request: https://projects.blender.org/blender/blender/pulls/123778 --- .../editors/sculpt_paint/paint_vertex.cc | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index db6e6dd4679..de3022114e9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -273,6 +273,22 @@ void init_session_data(const ToolSettings &ts, Object &ob) } } } + else if (ob.mode == OB_MODE_VERTEX_PAINT) { + /* Allocate scratch array for previous colors if needed. */ + SculptSession &ss = *ob.sculpt; + if (!vwpaint::brush_use_accumulate(*ts.vpaint)) { + if (ss.cache->prev_colors_vpaint.is_empty()) { + const Mesh *mesh = BKE_object_get_original_mesh(&ob); + const GVArray attribute = *mesh->attributes().lookup(mesh->active_color_attribute); + ss.cache->prev_colors_vpaint = GArray(attribute.type(), attribute.size()); + attribute.type().value_initialize_n(ss.cache->prev_colors_vpaint.data(), + ss.cache->prev_colors_vpaint.size()); + } + } + else { + ss.cache->prev_colors_vpaint = {}; + } + } } Vector pbvh_gather_generic(Object &ob, const VPaint &wp, const Brush &brush) @@ -743,26 +759,9 @@ static void paint_and_tex_color_alpha_intern(const VPaint &vp, } } -static void vertex_paint_init_stroke(Scene &scene, Depsgraph &depsgraph, Object &ob) +static void vertex_paint_init_stroke(Depsgraph &depsgraph, Object &ob) { vwpaint::init_stroke(depsgraph, ob); - - SculptSession &ss = *ob.sculpt; - ToolSettings &ts = *scene.toolsettings; - - /* Allocate scratch array for previous colors if needed. */ - if (!vwpaint::brush_use_accumulate(*ts.vpaint)) { - if (ss.cache->prev_colors_vpaint.is_empty()) { - const Mesh *mesh = BKE_object_get_original_mesh(&ob); - const GVArray attribute = *mesh->attributes().lookup(mesh->active_color_attribute); - ss.cache->prev_colors_vpaint = GArray(attribute.type(), attribute.size()); - attribute.type().value_initialize_n(ss.cache->prev_colors_vpaint.data(), - ss.cache->prev_colors_vpaint.size()); - } - } - else { - ss.cache->prev_colors_vpaint = {}; - } } /** \} */ @@ -999,7 +998,7 @@ static bool vpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo paint_stroke_set_mode_data(stroke, vpd); /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_stroke(scene, depsgraph, ob); + vertex_paint_init_stroke(depsgraph, ob); vwpaint::update_cache_invariants(C, vp, ss, op, mouse); vwpaint::init_session_data(ts, ob);