diff options
author | Jeroen Bakker <jeroen@blender.org> | 2022-03-15 14:05:43 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-03-15 14:05:43 +0300 |
commit | 018d9676cb68cc54d0342525e6682d10f209944e (patch) | |
tree | 3f112ed031b5a8644b7e143de14454e9d8498f8c | |
parent | ab1bf1e80e4a7820e06125f8532900d0f19768ae (diff) |
Face set automasking support.
4 files changed, 88 insertions, 31 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 8c3a13fe5b8..1447f2fc5f6 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -2325,15 +2325,15 @@ static float brush_strength(const Sculpt *sd, } } -float SCULPT_brush_strength_factor(SculptSession *ss, - const Brush *br, - const float brush_point[3], - const float len, - const float vno[3], - const float fno[3], - const float mask, - const int vertex_index, - const int thread_id) +float SCULPT_brush_strength_factor_custom_automask(SculptSession *ss, + const Brush *br, + const float brush_point[3], + const float len, + const float vno[3], + const float fno[3], + const float mask, + const float automask_factor, + const int thread_id) { StrokeCache *cache = ss->cache; const Scene *scene = cache->vc->scene; @@ -2417,11 +2417,27 @@ float SCULPT_brush_strength_factor(SculptSession *ss, avg *= 1.0f - mask; /* Auto-masking. */ - avg *= SCULPT_automasking_factor_get(cache->automasking, ss, vertex_index); + avg *= automask_factor; return avg; } +float SCULPT_brush_strength_factor(SculptSession *ss, + const Brush *br, + const float brush_point[3], + const float len, + const float vno[3], + const float fno[3], + const float mask, + const int vertex_index, + const int thread_id) +{ + const float automask_factor = SCULPT_automasking_factor_get( + ss->cache->automasking, ss, vertex_index); + return SCULPT_brush_strength_factor_custom_automask( + ss, br, brush_point, len, vno, fno, mask, automask_factor, thread_id); +} + bool SCULPT_search_sphere_cb(PBVHNode *node, void *data_v) { SculptSearchSphereData *data = data_v; diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 1776235e590..bbb908590ed 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -1133,6 +1133,15 @@ float SCULPT_brush_strength_factor(struct SculptSession *ss, float mask, int vertex_index, int thread_id); +float SCULPT_brush_strength_factor_custom_automask(struct SculptSession *ss, + const struct Brush *br, + const float point[3], + float len, + const float vno[3], + const float fno[3], + float mask, + float automask_factor, + int thread_id); /** * Tilts a normal by the x and y tilt values using the view axis. diff --git a/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc b/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc index 0f703c255e0..f4dc3f74504 100644 --- a/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc +++ b/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc @@ -40,13 +40,12 @@ namespace blender::ed::sculpt_paint::texture_paint { namespace painting { -static Pixel get_start_pixel(const PixelsPackage &encoded_pixels, - const Triangle &triangle, - const MVert *mvert, - const MLoopUV *ldata_uv) +static Pixel init_pixel(const Triangle &triangle, + const float3 weights, + const MVert *mvert, + const MLoopUV *ldata_uv) { Pixel result; - const float3 weights = encoded_pixels.start_edge_coord; interp_v3_v3v3v3(result.pos, mvert[triangle.vert_indices[0]].co, mvert[triangle.vert_indices[1]].co, @@ -57,10 +56,17 @@ static Pixel get_start_pixel(const PixelsPackage &encoded_pixels, ldata_uv[triangle.loop_indices[1]].uv, ldata_uv[triangle.loop_indices[2]].uv, weights); - return result; } +static Pixel get_start_pixel(const PixelsPackage &encoded_pixels, + const Triangle &triangle, + const MVert *mvert, + const MLoopUV *ldata_uv) +{ + return init_pixel(triangle, encoded_pixels.start_edge_coord, mvert, ldata_uv); +} + static Pixel get_delta_pixel(const PixelsPackage &encoded_pixels, const Triangle &triangle, const Pixel &start_pixel, @@ -69,18 +75,8 @@ static Pixel get_delta_pixel(const PixelsPackage &encoded_pixels, ) { - Pixel result; - const float3 weights = encoded_pixels.start_edge_coord + triangle.add_edge_coord_x; - interp_v3_v3v3v3(result.pos, - mvert[triangle.vert_indices[0]].co, - mvert[triangle.vert_indices[1]].co, - mvert[triangle.vert_indices[2]].co, - weights); - interp_v3_v3v3v3(result.uv, - ldata_uv[triangle.loop_indices[0]].uv, - ldata_uv[triangle.loop_indices[1]].uv, - ldata_uv[triangle.loop_indices[2]].uv, - weights); + Pixel result = init_pixel( + triangle, encoded_pixels.start_edge_coord + triangle.add_edge_coord_x, mvert, ldata_uv); result.pos -= start_pixel.pos; result.uv -= start_pixel.uv; return result; @@ -107,7 +103,11 @@ static void do_vertex_brush_test(void *__restrict userdata, PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin (ss->pbvh, node, vd, PBVH_ITER_UNIQUE) { - data->vertex_brush_tests[vd.index] = sculpt_brush_test_sq_fn(&test, vd.co); + if (sculpt_brush_test_sq_fn(&test, vd.co)) { + data->vertex_brush_tests[vd.index] = true; + } + data->automask_factors[vd.index] = SCULPT_automasking_factor_get( + ss->cache->automasking, ss, vd.index); } BKE_pbvh_vertex_iter_end; } @@ -143,12 +143,33 @@ static void do_task_cb_ex(void *__restrict userdata, * and faces only. */ std::vector<bool> triangle_brush_test_results(node_data->triangles.size()); int triangle_index = 0; + int last_poly_index = -1; for (Triangle &triangle : node_data->triangles) { for (int i = 0; i < 3; i++) { triangle_brush_test_results[triangle_index] = triangle_brush_test_results[triangle_index] || data->vertex_brush_tests[triangle.vert_indices[i]]; } + if (last_poly_index != triangle.poly_index) { + last_poly_index = triangle.poly_index; + float automasking_factor = 1.0f; + for (int t_index = triangle_index; + t_index < node_data->triangles.size() && + node_data->triangles[t_index].poly_index == triangle.poly_index; + t_index++) { + for (int i = 0; i < 3; i++) { + automasking_factor = min_ff(automasking_factor, + data->automask_factors[triangle.vert_indices[i]]); + } + } + + for (int t_index = triangle_index; + t_index < node_data->triangles.size() && + node_data->triangles[t_index].poly_index == triangle.poly_index; + t_index++) { + node_data->triangles[t_index].automasking_factor = automasking_factor; + } + } triangle_index += 1; } @@ -178,8 +199,16 @@ static void do_task_cb_ex(void *__restrict userdata, const float3 normal(0.0f, 0.0f, 0.0f); const float3 face_normal(0.0f, 0.0f, 0.0f); const float mask = 0.0f; - const float falloff_strength = SCULPT_brush_strength_factor( - ss, brush, pixel.pos, sqrtf(test.dist), normal, face_normal, mask, 0, thread_id); + const float falloff_strength = SCULPT_brush_strength_factor_custom_automask( + ss, + brush, + pixel.pos, + sqrtf(test.dist), + normal, + face_normal, + mask, + triangle.automasking_factor, + thread_id); blend_color_interpolate_float(color, color, brush_linear, falloff_strength * brush_strength); pixels_painted = true; @@ -249,6 +278,7 @@ void SCULPT_do_texture_paint_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int data.brush = brush; data.nodes = nodes; data.vertex_brush_tests = std::vector<bool>(mesh->totvert); + data.automask_factors = Vector<float>(mesh->totvert); TaskParallelSettings settings; BKE_pbvh_parallel_range_settings(&settings, true, totnode); diff --git a/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh b/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh index b57e59aa11c..e287d04b676 100644 --- a/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh @@ -8,6 +8,7 @@ struct Triangle { int3 vert_indices; int poly_index; float3 add_edge_coord_x; + float automasking_factor; }; struct PixelsPackage { @@ -156,6 +157,7 @@ struct TexturePaintingUserData { Brush *brush; PBVHNode **nodes; std::vector<bool> vertex_brush_tests; + Vector<float> automask_factors; }; } // namespace blender::ed::sculpt_paint::texture_paint |