diff options
author | Falk David <filedescriptor> | 2022-04-28 13:37:10 +0300 |
---|---|---|
committer | Falk David <falkdavid@gmx.de> | 2022-04-28 13:38:28 +0300 |
commit | 16fe767d0090f3ff2b2c45c63cb4a84805991f3a (patch) | |
tree | 2a43c970efb289755c5c3ad84260582eef5fb236 /source/blender | |
parent | e8102aea13f510daa114eadee754803c380736a9 (diff) |
GPencil: Fix offset modifier performance regression
When using an offset modifier on a grease pencil object, the performance
could be impacted due to the randomize option introduced by rB6a2bc40e0131.
Even if the option was not used (offset, rotation, scale set to zero), the modifier
would still compute the random transformation matrix.
The patch checks if the randomization is used and only then caluclates the matrix.
Reviewed By: #grease_pencil, antoniov
Differential Revision: https://developer.blender.org/D14553
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c index 4fe92ab925d..f201a147082 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c @@ -83,6 +83,9 @@ static void deformStroke(GpencilModifierData *md, return; } + const bool is_randomized = !(is_zero_v3(mmd->rnd_offset) && is_zero_v3(mmd->rnd_rot) && + is_zero_v3(mmd->rnd_scale)); + int seed = mmd->seed; /* Make sure different modifiers get different seeds. */ seed += BLI_hash_string(ob->id.name + 2); @@ -91,25 +94,27 @@ static void deformStroke(GpencilModifierData *md, float rand[3][3]; float rand_offset = BLI_hash_int_01(seed); - /* Get stroke index for random offset. */ - int rnd_index = BLI_findindex(&gpf->strokes, gps); - for (int j = 0; j < 3; j++) { - const uint primes[3] = {2, 3, 7}; - double offset[3] = {0.0f, 0.0f, 0.0f}; - double r[3]; - /* To ensure a nice distribution, we use halton sequence and offset using the seed. */ - BLI_halton_3d(primes, offset, rnd_index, r); - - if ((mmd->flag & GP_OFFSET_UNIFORM_RANDOM_SCALE) && j == 2) { - float rand_value; - rand_value = fmodf(r[0] * 2.0f - 1.0f + rand_offset, 1.0f); - rand_value = fmodf(sin(rand_value * 12.9898f + j * 78.233f) * 43758.5453f, 1.0f); - copy_v3_fl(rand[j], rand_value); - } - else { - for (int i = 0; i < 3; i++) { - rand[j][i] = fmodf(r[i] * 2.0f - 1.0f + rand_offset, 1.0f); - rand[j][i] = fmodf(sin(rand[j][i] * 12.9898f + j * 78.233f) * 43758.5453f, 1.0f); + if (is_randomized) { + /* Get stroke index for random offset. */ + int rnd_index = BLI_findindex(&gpf->strokes, gps); + for (int j = 0; j < 3; j++) { + const uint primes[3] = {2, 3, 7}; + double offset[3] = {0.0f, 0.0f, 0.0f}; + double r[3]; + /* To ensure a nice distribution, we use halton sequence and offset using the seed. */ + BLI_halton_3d(primes, offset, rnd_index, r); + + if ((mmd->flag & GP_OFFSET_UNIFORM_RANDOM_SCALE) && j == 2) { + float rand_value; + rand_value = fmodf(r[0] * 2.0f - 1.0f + rand_offset, 1.0f); + rand_value = fmodf(sin(rand_value * 12.9898f + j * 78.233f) * 43758.5453f, 1.0f); + copy_v3_fl(rand[j], rand_value); + } + else { + for (int i = 0; i < 3; i++) { + rand[j][i] = fmodf(r[i] * 2.0f - 1.0f + rand_offset, 1.0f); + rand[j][i] = fmodf(sin(rand[j][i] * 12.9898f + j * 78.233f) * 43758.5453f, 1.0f); + } } } } @@ -128,21 +133,23 @@ static void deformStroke(GpencilModifierData *md, } /* Calculate Random matrix. */ - float mat_rnd[4][4]; - float rnd_loc[3], rnd_rot[3], rnd_scale_weight[3]; - float rnd_scale[3] = {1.0f, 1.0f, 1.0f}; - - mul_v3_v3fl(rnd_loc, rand[0], weight); - mul_v3_v3fl(rnd_rot, rand[1], weight); - mul_v3_v3fl(rnd_scale_weight, rand[2], weight); - - mul_v3_v3v3(rnd_loc, mmd->rnd_offset, rnd_loc); - mul_v3_v3v3(rnd_rot, mmd->rnd_rot, rnd_rot); - madd_v3_v3v3(rnd_scale, mmd->rnd_scale, rnd_scale_weight); - - loc_eul_size_to_mat4(mat_rnd, rnd_loc, rnd_rot, rnd_scale); - /* Apply randomness matrix. */ - mul_m4_v3(mat_rnd, &pt->x); + if (is_randomized) { + float mat_rnd[4][4]; + float rnd_loc[3], rnd_rot[3], rnd_scale_weight[3]; + float rnd_scale[3] = {1.0f, 1.0f, 1.0f}; + + mul_v3_v3fl(rnd_loc, rand[0], weight); + mul_v3_v3fl(rnd_rot, rand[1], weight); + mul_v3_v3fl(rnd_scale_weight, rand[2], weight); + + mul_v3_v3v3(rnd_loc, mmd->rnd_offset, rnd_loc); + mul_v3_v3v3(rnd_rot, mmd->rnd_rot, rnd_rot); + madd_v3_v3v3(rnd_scale, mmd->rnd_scale, rnd_scale_weight); + + loc_eul_size_to_mat4(mat_rnd, rnd_loc, rnd_rot, rnd_scale); + /* Apply randomness matrix. */ + mul_m4_v3(mat_rnd, &pt->x); + } /* Calculate matrix. */ mul_v3_v3fl(loc, mmd->loc, weight); |