diff options
-rw-r--r-- | source/blender/blenlib/BLI_rand.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h index 0ef971bf41f..69b23b2473f 100644 --- a/source/blender/blenlib/BLI_rand.h +++ b/source/blender/blenlib/BLI_rand.h @@ -106,6 +106,7 @@ int BLI_rng_thread_rand(RNG_THREAD_ARRAY *rngarr, int thread) ATTR_WARN_UNUSED /** Return the _n_th number of the given low-discrepancy sequence. */ void BLI_halton_1D(unsigned int prime, double offset, int n, double *r); void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r); +void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r); void BLI_hammersley_1D(unsigned int n, double *r); /** Return the whole low-discrepancy sequence up to _n_. */ diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index a501d38abb7..9ab39dda9d0 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -402,6 +402,17 @@ void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r) } } +void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r) +{ + const double invprimes[3] = {1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]}; + + for (int s = 0; s < n; s++) { + for (int i = 0; i < 3; i++) { + r[i] = halton_ex(invprimes[i], &offset[i]); + } + } +} + void BLI_halton_2D_sequence(unsigned int prime[2], double offset[2], int n, double *r) { const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]}; |