From afb4b65167165613f177a531bd3d4dcb3649c1c6 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 15 Apr 2013 23:12:40 +0000 Subject: Random number generator: replace a bunch of usage of the global random number generator with a local one. It's not thread safe and will not give repeatable results, so in most cases it should not be used. Also fixes #34992 where the noise texture of a displacement modifier was not properly random in opengl animation render, because the seed got reset to a fixed value by an unrelated function while for final render it changed each frame. --- source/blender/blenlib/intern/jitter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source/blender/blenlib/intern/jitter.c') diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c index 3fe0ef158df..7141bedcf05 100644 --- a/source/blender/blenlib/intern/jitter.c +++ b/source/blender/blenlib/intern/jitter.c @@ -139,6 +139,7 @@ void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2) void BLI_jitter_init(float *jitarr, int num) { float *jit2, x, rad1, rad2, rad3; + RNG *rng; int i; if (num == 0) return; @@ -148,15 +149,18 @@ void BLI_jitter_init(float *jitarr, int num) rad2 = 1.0f / ((float)num); rad3 = sqrtf((float)num) / ((float)num); - BLI_srand(31415926 + num); + rng = BLI_rng_new(31415926 + num); + x = 0; for (i = 0; i < 2 * num; i += 2) { - jitarr[i] = x + rad1 * (float)(0.5 - BLI_drand()); - jitarr[i + 1] = ((float)i / 2) / num + rad1 * (float)(0.5 - BLI_drand()); + jitarr[i] = x + rad1 * (float)(0.5 - BLI_rng_get_double(rng)); + jitarr[i + 1] = ((float)i / 2) / num + rad1 * (float)(0.5 - BLI_rng_get_double(rng)); x += rad3; x -= floorf(x); } + BLI_rng_free(rng); + for (i = 0; i < 24; i++) { BLI_jitterate1(jitarr, jit2, num, rad1); BLI_jitterate1(jitarr, jit2, num, rad1); -- cgit v1.2.3