diff options
Diffstat (limited to 'source/blender/gpencil_modifiers')
-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); |