[Bf-blender-cvs] [67408ac9399] greasepencil-object: GPencil: Modifier: Rework Array modifier's RNG for better random variation

Clément Foucault noreply at git.blender.org
Thu Mar 5 18:29:34 CET 2020


Commit: 67408ac9399ea59e91113779a6df4aefd3ad1f99
Author: Clément Foucault
Date:   Thu Mar 5 18:29:27 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rB67408ac9399ea59e91113779a6df4aefd3ad1f99

GPencil: Modifier: Rework Array modifier's RNG for better random variation

Use a mix of low decrepency sequence with a special sin rand function
to avoid repeating patterns. This should suffice in most cases

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

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

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
index b2995ea4e76..1fc8c19b542 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
@@ -190,6 +190,8 @@ static void generate_geometry(GpencilModifierData *md,
     float current_offset[4][4];
     unit_m4(current_offset);
 
+    float rand_offset = BLI_hash_int_01(seed);
+
     for (int x = 0; x < mmd->count; x++) {
       /* original strokes are at index = 0 */
       if (x == 0) {
@@ -216,14 +218,26 @@ static void generate_geometry(GpencilModifierData *md,
         madd_v3_v3fl(current_offset[3], relative, x);
       }
 
+      float rand[3][3];
+      for (int j = 0; j < 3; j++) {
+        uint primes[3] = {2, 3, 7};
+        double offset[3] = {0.0, 0.0, 0.0};
+        double r[3];
+        /* To ensure a nice distribution, we use halton sequence and offset using the seed. */
+        BLI_halton_3d(primes, offset, x, r);
+
+        for (int i = 0; i < 3; i++) {
+          rand[j][i] = fmodf(r[i] * 2.0 - 1.0 + rand_offset, 1.0f);
+          rand[j][i] = fmodf(sin(rand[j][i] * 12.9898 + j * 78.233) * 43758.5453, 1.0f);
+        }
+      }
       /* Calculate Random matrix. */
       float mat_rnd[4][4];
       float loc[3], rot[3];
       float scale[3] = {1.0f, 1.0f, 1.0f};
-      float factor = BLI_hash_int_01((uint)seed + x) * 2.0f - 1.0f;
-      mul_v3_v3fl(loc, mmd->rnd_offset, factor);
-      mul_v3_v3fl(rot, mmd->rnd_rot, factor);
-      madd_v3_v3fl(scale, mmd->rnd_scale, factor);
+      mul_v3_v3v3(loc, mmd->rnd_offset, rand[0]);
+      mul_v3_v3v3(rot, mmd->rnd_rot, rand[1]);
+      madd_v3_v3v3(scale, mmd->rnd_scale, rand[2]);
 
       loc_eul_size_to_mat4(mat_rnd, loc, rot, scale);



More information about the Bf-blender-cvs mailing list