Fix T95185: Invalid normals after undo in sculpt mode

Since d9c6ceb3b88b6db87490b08e0089f9a18e6c52d6 partial updates to
normals in sculpt-mode were accumulating into the current normal
instead of a zeroed value.

Zero vertex normal values tagged for calculation before accumulation.

Reviewed By: HooglyBoogly

Ref D13975
This commit is contained in:
Campbell Barton 2022-02-01 13:39:48 +11:00
parent 9ce1135440
commit c8814fb610
Notes: blender-bot 2023-06-21 19:23:24 +02:00
Referenced by issue #95843, Undo after remeshing or dyntopo creates a flat shading on normals
Referenced by issue #95185, Invalid normals after undo in sculpt mode
1 changed files with 24 additions and 0 deletions

View File

@ -1007,6 +1007,28 @@ typedef struct PBVHUpdateData {
bool show_sculpt_face_sets;
} PBVHUpdateData;
static void pbvh_update_normals_clear_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
{
PBVHUpdateData *data = userdata;
PBVH *pbvh = data->pbvh;
PBVHNode *node = data->nodes[n];
float(*vnors)[3] = data->vnors;
if (node->flag & PBVH_UpdateNormals) {
const int *verts = node->vert_indices;
const int totvert = node->uniq_verts;
for (int i = 0; i < totvert; i++) {
const int v = verts[i];
const MVert *mvert = &pbvh->verts[v];
if (mvert->flag & ME_VERT_PBVH_UPDATE) {
zero_v3(vnors[v]);
}
}
}
}
static void pbvh_update_normals_accum_task_cb(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict UNUSED(tls))
@ -1107,6 +1129,8 @@ static void pbvh_faces_update_normals(PBVH *pbvh, PBVHNode **nodes, int totnode)
TaskParallelSettings settings;
BKE_pbvh_parallel_range_settings(&settings, true, totnode);
/* Zero normals before accumulation. */
BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_clear_task_cb, &settings);
BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_accum_task_cb, &settings);
BLI_task_parallel_range(0, totnode, &data, pbvh_update_normals_store_task_cb, &settings);
}