Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-16 03:12:40 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-16 03:12:40 +0400
commitafb4b65167165613f177a531bd3d4dcb3649c1c6 (patch)
tree32e1446b5fc3ce8ec00fa0e8b9e0fcb2eedda127 /source/blender/blenlib/intern/jitter.c
parent638b084f824bc345468bc8e02422b5da65a641a7 (diff)
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.
Diffstat (limited to 'source/blender/blenlib/intern/jitter.c')
-rw-r--r--source/blender/blenlib/intern/jitter.c10
1 files changed, 7 insertions, 3 deletions
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);