Fix: Performance regression when using bevel and subdivision modifier
PR https://projects.blender.org/blender/blender/pulls/144233. Fix #142296 performance regression caused by merging UV positions based on face area weights, replacing it with mean average weights computation. The former method resulted in higher probability in making subdivision cache invalid between frame updates and thus causing expensive recreation of blender::bke::subdiv::OpenSubdiv_Evaluator object. While this fix isn't directly answering a question why specific UV position updates would cause this reevaluation of subdivision object, it fixes the performance regression caused by #139595 PR.
This commit is contained in:
committed by
Howard Trickey
parent
1b559b4f78
commit
7e4defbf3b
@@ -814,24 +814,19 @@ static void bevel_merge_uvs(BevelParams *bp, BMesh *bm)
|
||||
int uv_data_offset = CustomData_get_n_offset(&bm->ldata, CD_PROP_FLOAT2, i);
|
||||
for (Vector<UVVertBucket> &uv_vert_buckets : bp->uv_vert_maps[i].values()) {
|
||||
for (UVVertBucket &uv_vert_bucket : uv_vert_buckets) {
|
||||
/* Using face weights instead of mean average because it produces slightly better results,
|
||||
* although this is purely empirical and subjective. */
|
||||
float weight_sum = 0.0f;
|
||||
int num_uv_verts = uv_vert_bucket.size();
|
||||
if (num_uv_verts <= 1) {
|
||||
continue;
|
||||
}
|
||||
float uv[2] = {0.0f, 0.0f};
|
||||
for (BMLoop *l : uv_vert_bucket) {
|
||||
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, uv_data_offset);
|
||||
float weighted_luv[2] = {0.0f, 0.0f};
|
||||
float face_area = BM_face_calc_area(l->f);
|
||||
mul_v2_v2fl(weighted_luv, luv, face_area);
|
||||
add_v2_v2(uv, weighted_luv);
|
||||
weight_sum += face_area;
|
||||
add_v2_v2(uv, luv);
|
||||
}
|
||||
if (uv_vert_bucket.size() > 1 && weight_sum > 0.0f) {
|
||||
mul_v2_fl(uv, 1.0f / weight_sum);
|
||||
for (BMLoop *l : uv_vert_bucket) {
|
||||
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, uv_data_offset);
|
||||
copy_v2_v2(luv, uv);
|
||||
}
|
||||
mul_v2_fl(uv, 1.0f / (float)num_uv_verts);
|
||||
for (BMLoop *l : uv_vert_bucket) {
|
||||
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, uv_data_offset);
|
||||
copy_v2_v2(luv, uv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
tests/files/modeling/bevel_regression.blend
(Stored with Git LFS)
BIN
tests/files/modeling/bevel_regression.blend
(Stored with Git LFS)
Binary file not shown.
BIN
tests/files/modeling/modifiers.blend
(Stored with Git LFS)
BIN
tests/files/modeling/modifiers.blend
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user