diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-06-20 06:21:11 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-06-20 07:39:13 +0300 |
commit | 513f566b40a5bde4d89797aecf7c0ad3e4d1a20b (patch) | |
tree | 40949ae61aef858a7e3f8710abdc56f4e7da4f70 /source/blender/render | |
parent | b5e5fbcfc81b6ca4968d0788b5e6e330205d298b (diff) |
Mesh: optimize object mode face tessellation
- Multi-thread BKE_mesh_recalc_looptri.
- Add BKE_mesh_recalc_looptri_with_normals,
this skips having to calculate normals for ngons.
Exact performance depends on number of faces, size of ngons and
available CPU cores.
For high poly meshes the isolated improvement to BKE_mesh_recalc_looptri
in my tests was between 6.7x .. 25.0x, with the largest gains seen in
meshes containing ngons with many sides.
The overall speedup for high poly meshes containing quads and triangles
is only ~20% although ngon heavy meshes can be much faster.
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/intern/bake.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c index 416d85ce1a3..011bdb056d8 100644 --- a/source/blender/render/intern/bake.c +++ b/source/blender/render/intern/bake.c @@ -466,7 +466,16 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__); triangles = MEM_callocN(sizeof(TriTessFace) * tottri, __func__); - BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri); + const float(*precomputed_normals)[3] = CustomData_get_layer(&me->pdata, CD_NORMAL); + const bool calculate_normal = precomputed_normals ? false : true; + + if (precomputed_normals != NULL) { + BKE_mesh_recalc_looptri_with_normals( + me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri, precomputed_normals); + } + else { + BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri); + } if (tangent) { BKE_mesh_ensure_normals_for_display(me_eval); @@ -479,9 +488,6 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval loop_normals = CustomData_get_layer(&me_eval->ldata, CD_NORMAL); } - const float(*precomputed_normals)[3] = CustomData_get_layer(&me->pdata, CD_NORMAL); - const bool calculate_normal = precomputed_normals ? false : true; - for (i = 0; i < tottri; i++) { const MLoopTri *lt = &looptri[i]; const MPoly *mp = &me->mpoly[lt->poly]; |