diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-10-09 17:48:38 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-10-09 17:48:52 +0400 |
commit | 016e75ad64935775b487e6674f7c2a4f084cd7fe (patch) | |
tree | 480c12bd68e7786d4d5d9fd7a5a00b44f8e3f711 /source/blender/blenlib/intern/rand.c | |
parent | 127b92de838c0f27c27aad3237032d82d7fbd501 (diff) |
Fix T42139, vertical noise stripe patterns in noise texture.
Two fixes here (only the second one is strictly needed to fix the issue,
but both make the system better).
First is introduction of a random generator array for use with threaded
systems where each thread needs to access its own number generator.
The random texture now uses this so it should not be influenced by other
random generator reseedings of the main random generator like it did
before.
Second, I reshuffled the texture code to resample the upper bits of the
random number first. According to Numerical Recipes, this is where the
most variance can be found, so by sampling those we avoid correlation
issues. Also, multiplying here is not ideal because if a pair of bits
are zero, then the whole result will also be zero.
Overall this is much more random (tm) than before, however result will
also be brighter, since we now have less black spots. Tweaking the
brightness/contrast should somewhat fix that, generally having the same
result as before is not possible anyway if we are to really fix this.
Also, seems like exposing procedural depth might be nice here since it
influences the precision of the texture lookup.
Diffstat (limited to 'source/blender/blenlib/intern/rand.c')
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 3dff0b31091..70780f9d47d 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -245,3 +245,29 @@ float BLI_thread_frand(int thread) return BLI_rng_get_float(&rng_tab[thread]); } +struct RNG_THREAD_ARRAY { + RNG rng_tab[BLENDER_MAX_THREADS]; +}; + +RNG_THREAD_ARRAY *BLI_rng_threaded_new(void) +{ + unsigned int i; + RNG_THREAD_ARRAY *rngarr = MEM_mallocN(sizeof(RNG_THREAD_ARRAY), "random_array"); + + for (i = 0; i < BLENDER_MAX_THREADS; i++) { + BLI_rng_srandom(&rngarr->rng_tab[i], (unsigned int)(rngarr->rng_tab[i].X * 257)); + } + + return rngarr; +} + +void BLI_rng_threaded_free(struct RNG_THREAD_ARRAY *rngarr) +{ + MEM_freeN(rngarr); +} + +int BLI_rng_thread_rand(RNG_THREAD_ARRAY *rngarr, int thread) +{ + return BLI_rng_get_int(&rngarr->rng_tab[thread]); +} + |