Fix artifact in Clay Strips when producing large deformations

The clay strips brush tip tests distances against a cube with beveled Z
aligned edges. This cube was positioned with its center in the surface
of the mesh, so when producing large deformation, some vertices that
should be deformed were positioned further than the cube's Z dimension,
so they were left behind, producing artifacts.
This displaces and deforms the local space to position the brush tip
cube (now a prism) towards the deformation direction, so more vertices
can be included, removing most of these artifacts.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D8004
This commit is contained in:
Pablo Dobarro 2020-06-22 01:01:42 +02:00
parent 255638d223
commit 560a73610b
1 changed files with 18 additions and 1 deletions

View File

@ -4706,6 +4706,17 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
mul_v3_fl(temp, displace);
add_v3_v3(area_co, temp);
/* Clay Strips uses a cube test with falloff in the XY axis (not in Z) and a plane to deform the
* vertices. When in Add mode, vertices that are below the plane and inside the cube are move
* towards the plane. In this situation, there may be cases where a vertex is outside the cube
* but below the plane, so won't be deformed, causing artifacts. In order to prevent these
* artifacts, this displaces the test cube space in relation to the plane in order to
* deform more vertices that may be below it. */
/* The 0.7 and 1.25 factors are arbitrary and don't have any relation between them, they were set
* by doing multiple tests using the defaul Clay Strips brush preset. */
float area_co_displaced[3];
madd_v3_v3v3fl(area_co_displaced, area_co, area_no, -radius * 0.7f);
/* Init brush local space matrix. */
cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry);
mat[0][3] = 0.0f;
@ -4713,13 +4724,19 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
mat[1][3] = 0.0f;
copy_v3_v3(mat[2], area_no);
mat[2][3] = 0.0f;
copy_v3_v3(mat[3], ss->cache->location);
copy_v3_v3(mat[3], area_co_displaced);
mat[3][3] = 1.0f;
normalize_m4(mat);
/* Scale brush local space matrix. */
scale_m4_fl(scale, ss->cache->radius);
mul_m4_m4m4(tmat, mat, scale);
/* Deform the local space in Z to scale the test cube. As the test cube does not have falloff in
* Z this does not produce artifacts in the falloff cube and allows to deform extra vertices
* during big deformation while keeping the surface as uniform as possible. */
mul_v3_fl(tmat[2], 1.25f);
invert_m4_m4(mat, tmat);
SculptThreadedTaskData data = {