[Bf-blender-cvs] [16fe767d009] master: GPencil: Fix offset modifier performance regression

Falk David noreply at git.blender.org
Thu Apr 28 12:39:02 CEST 2022


Commit: 16fe767d0090f3ff2b2c45c63cb4a84805991f3a
Author: Falk David
Date:   Thu Apr 28 12:37:10 2022 +0200
Branches: master
https://developer.blender.org/rB16fe767d0090f3ff2b2c45c63cb4a84805991f3a

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

===================================================================

M	source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list