From 8c7708acbc15a127946bb9c6d99dccb27f7b6d24 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 28 May 2024 15:56:46 -0400 Subject: [PATCH] Cleanup: Paint: Remove multires code paths from vertex & weight paint Multires isn't supported here anyway, and if it was it would look very different because the weights and colors would probably be stored on the subdivided grids somehow. For now this code is just confusing and gets in the way. It also mixes up the purpose of the PBVH iteration macro abstraction. --- .../editors/sculpt_paint/paint_vertex.cc | 51 ++++--------------- .../editors/sculpt_paint/paint_weight.cc | 32 +++--------- 2 files changed, 17 insertions(+), 66 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index e9e4fb4b7ec..511c21a23bd 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -1029,9 +1029,6 @@ static void do_vpaint_brush_blur_loops(bContext *C, const Brush &brush = *ob.sculpt->cache->brush; const Scene &scene = *CTX_data_scene(C); - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); - const SculptVertexPaintGeomMap *gmap = &ss.mode.vpaint.gmap; const StrokeCache *cache = ss.cache; float brush_size_pressure, brush_alpha_value, brush_alpha_pressure; @@ -1065,11 +1062,7 @@ static void do_vpaint_brush_blur_loops(bContext *C, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : - vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected for painting. */ if (use_vert_sel && !select_vert[vert]) { @@ -1148,7 +1141,7 @@ static void do_vpaint_brush_blur_loops(bContext *C, color_orig = previous_color[corner]; } const float final_alpha = Traits::range * brush_fade * brush_strength * - brush_alpha_pressure * grid_alpha; + brush_alpha_pressure; /* Mix the new color with the original * based on the brush strength and the curve. */ colors[corner] = vpaint_blend( @@ -1174,9 +1167,6 @@ static void do_vpaint_brush_blur_verts(bContext *C, const Brush &brush = *ss.cache->brush; const Scene &scene = *CTX_data_scene(C); - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); - const SculptVertexPaintGeomMap *gmap = &ss.mode.vpaint.gmap; const StrokeCache *cache = ss.cache; float brush_size_pressure, brush_alpha_value, brush_alpha_pressure; @@ -1210,11 +1200,7 @@ static void do_vpaint_brush_blur_verts(bContext *C, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : - vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected for painting. */ if (use_vert_sel && !select_vert[vert]) { @@ -1280,7 +1266,7 @@ static void do_vpaint_brush_blur_verts(bContext *C, color_orig = previous_color[vert]; } const float final_alpha = Traits::range * brush_fade * brush_strength * - brush_alpha_pressure * grid_alpha; + brush_alpha_pressure; /* Mix the new color with the original * based on the brush strength and the curve. */ colors[vert] = vpaint_blend(vp, @@ -1311,8 +1297,6 @@ static void do_vpaint_brush_smear(bContext *C, if (!cache->is_last_valid) { return; } - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const Brush &brush = *ob.sculpt->cache->brush; const Scene &scene = *CTX_data_scene(C); @@ -1357,11 +1341,7 @@ static void do_vpaint_brush_smear(bContext *C, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : - vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; const float3 &mv_curr = ss.vert_positions[vert]; /* if the vertex is selected for painting. */ @@ -1446,7 +1426,7 @@ static void do_vpaint_brush_smear(bContext *C, } const float final_alpha = Traits::range * brush_fade * brush_strength * - brush_alpha_pressure * grid_alpha; + brush_alpha_pressure; /* For each face owning this vert, * paint each loop belonging to this vert. */ @@ -1502,8 +1482,6 @@ static void calculate_average_color(VPaintData &vpd, Span nodes) { SculptSession &ss = *ob.sculpt; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const SculptVertexPaintGeomMap *gmap = &ss.mode.vpaint.gmap; StrokeCache *cache = ss.cache; @@ -1543,8 +1521,7 @@ static void calculate_average_color(VPaintData &vpd, if (BKE_brush_curve_strength(&brush, 0.0, cache->radius) <= 0.0f) { continue; } - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : - vd.vert_indices[vd.i]; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected for painting. */ if (use_vert_sel && !select_vert[vert]) { continue; @@ -1619,12 +1596,10 @@ static void vpaint_do_draw(bContext *C, GMutableSpan attribute) { SculptSession &ss = *ob.sculpt; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); const Brush &brush = *ob.sculpt->cache->brush; const Scene &scene = *CTX_data_scene(C); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const SculptVertexPaintGeomMap *gmap = &ss.mode.vpaint.gmap; const StrokeCache *cache = ss.cache; @@ -1659,18 +1634,12 @@ static void vpaint_do_draw(bContext *C, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* NOTE: Grids are 1:1 with corners (aka loops). - * For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : - vd.vert_indices[vd.i]; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected for painting. */ if (use_vert_sel && !select_vert[vert]) { continue; } - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; - /* Calc the dot prod. between ray norm on surf and current vert * (ie splash prevention factor), and only paint front facing verts. */ float brush_strength = cache->bstrength; @@ -1724,7 +1693,7 @@ static void vpaint_do_draw(bContext *C, color_orig = previous_color[vert]; } const float final_alpha = Traits::frange * brush_fade * brush_strength * tex_alpha * - brush_alpha_pressure * grid_alpha; + brush_alpha_pressure; colors[vert] = vpaint_blend(vp, colors[vert], @@ -1752,7 +1721,7 @@ static void vpaint_do_draw(bContext *C, color_orig = previous_color[corner]; } const float final_alpha = Traits::frange * brush_fade * brush_strength * tex_alpha * - brush_alpha_pressure * grid_alpha; + brush_alpha_pressure; /* Mix the new color with the original based on final_alpha. */ colors[corner] = vpaint_blend(vp, diff --git a/source/blender/editors/sculpt_paint/paint_weight.cc b/source/blender/editors/sculpt_paint/paint_weight.cc index 03592ee51e8..069e4200aad 100644 --- a/source/blender/editors/sculpt_paint/paint_weight.cc +++ b/source/blender/editors/sculpt_paint/paint_weight.cc @@ -1070,8 +1070,6 @@ static void do_wpaint_brush_blur_task(const Scene &scene, { using namespace blender; SculptSession &ss = *ob.sculpt; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const SculptVertexPaintGeomMap *gmap = &ss.mode.wpaint.gmap; const StrokeCache *cache = ss.cache; @@ -1100,10 +1098,7 @@ static void do_wpaint_brush_blur_task(const Scene &scene, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected */ if ((use_face_sel || use_vert_sel) && !select_vert[vert]) { continue; @@ -1133,7 +1128,7 @@ static void do_wpaint_brush_blur_task(const Scene &scene, } const float brush_fade = BKE_brush_curve_strength(&brush, sqrtf(test.dist), cache->radius); - const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; + const float final_alpha = brush_fade * brush_strength * brush_alpha_pressure; if ((brush.flag & BRUSH_ACCUMULATE) == 0) { if (ss.mode.wpaint.alpha_weight[vert] < final_alpha) { @@ -1162,8 +1157,6 @@ static void do_wpaint_brush_smear_task(const Scene &scene, { using namespace blender; SculptSession &ss = *ob.sculpt; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const SculptVertexPaintGeomMap *gmap = &ss.mode.wpaint.gmap; const StrokeCache *cache = ss.cache; @@ -1203,10 +1196,7 @@ static void do_wpaint_brush_smear_task(const Scene &scene, continue; } - /* For grid based pbvh, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; const float3 &mv_curr = ss.vert_positions[vert]; /* If the vertex is selected */ @@ -1257,7 +1247,7 @@ static void do_wpaint_brush_smear_task(const Scene &scene, continue; } const float brush_fade = BKE_brush_curve_strength(&brush, sqrtf(test.dist), cache->radius); - const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; + const float final_alpha = brush_fade * brush_strength * brush_alpha_pressure; if (final_alpha <= 0.0f) { continue; @@ -1281,8 +1271,6 @@ static void do_wpaint_brush_draw_task(const Scene &scene, { using namespace blender; SculptSession &ss = *ob.sculpt; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const StrokeCache *cache = ss.cache; /* NOTE: normally `BKE_brush_weight_get(scene, brush)` is used, @@ -1312,11 +1300,7 @@ static void do_wpaint_brush_draw_task(const Scene &scene, if (!sculpt_brush_test_sq_fn(test, vd.co)) { continue; } - /* NOTE: grids are 1:1 with corners (aka loops). - * For multires, take the vert whose loop corresponds to the current grid. - * Otherwise, take the current vert. */ - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : vd.vert_indices[vd.i]; - const float grid_alpha = has_grids ? 1.0f / vd.gridsize : 1.0f; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected */ if ((use_face_sel || use_vert_sel) && !select_vert[vert]) { @@ -1331,7 +1315,7 @@ static void do_wpaint_brush_draw_task(const Scene &scene, continue; } const float brush_fade = BKE_brush_curve_strength(&brush, sqrtf(test.dist), cache->radius); - const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; + const float final_alpha = brush_fade * brush_strength * brush_alpha_pressure; if ((brush.flag & BRUSH_ACCUMULATE) == 0) { if (ss.mode.wpaint.alpha_weight[vert] < final_alpha) { @@ -1357,8 +1341,6 @@ static WPaintAverageAccum do_wpaint_brush_calc_average_weight(Object &ob, using namespace blender; SculptSession &ss = *ob.sculpt; StrokeCache *cache = ss.cache; - const PBVHType pbvh_type = BKE_pbvh_type(*ss.pbvh); - const bool has_grids = (pbvh_type == PBVH_GRIDS); const bool use_normal = vwpaint::use_normal(vp); const bool use_face_sel = (mesh.editflag & ME_EDIT_PAINT_FACE_SEL) != 0; @@ -1394,7 +1376,7 @@ static WPaintAverageAccum do_wpaint_brush_calc_average_weight(Object &ob, continue; } - const int vert = has_grids ? ss.corner_verts[vd.grid_indices[vd.g]] : vd.vert_indices[vd.i]; + const int vert = vd.vert_indices[vd.i]; /* If the vertex is selected. */ if ((use_face_sel || use_vert_sel) && !select_vert[vert]) { continue;