Blender  V3.3
sobol.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2008, Frances Y. Kuo and Stephen Joe
4  * All rights reserved. */
5 
6 /*
7  * Sobol sequence direction vectors.
8  *
9  * This file contains code to create direction vectors for generating sobol
10  * sequences in high dimensions. It is adapted from code on this webpage:
11  *
12  * http://web.maths.unsw.edu.au/~fkuo/sobol/
13  *
14  * From these papers:
15  *
16  * S. Joe and F. Y. Kuo, Remark on Algorithm 659: Implementing Sobol's quasirandom
17  * sequence generator, ACM Trans. Math. Softw. 29, 49-57 (2003)
18  *
19  * S. Joe and F. Y. Kuo, Constructing Sobol sequences with better two-dimensional
20  * projections, SIAM J. Sci. Comput. 30, 2635-2654 (2008)
21  */
22 
23 #include "util/types.h"
24 
25 #include "scene/sobol.h"
26 
28 
29 #include "scene/sobol.tables"
30 
31 void sobol_generate_direction_vectors(uint vectors[][SOBOL_BITS], int dimensions)
32 {
33  assert(dimensions <= SOBOL_MAX_DIMENSIONS);
34 
35  const uint L = SOBOL_BITS;
36 
37  /* first dimension is exception */
38  uint *v = vectors[0];
39 
40  for (uint i = 0; i < L; i++)
41  v[i] = 1 << (31 - i); // all m's = 1
42 
43  for (int dim = 1; dim < dimensions; dim++) {
44  const SobolDirectionNumbers *numbers = &SOBOL_NUMBERS[dim - 1];
45  const uint s = numbers->s;
46  const uint a = numbers->a;
47  const uint *m = numbers->m;
48 
49  v = vectors[dim];
50 
51  if (L <= s) {
52  for (uint i = 0; i < L; i++)
53  v[i] = m[i] << (31 - i);
54  }
55  else {
56  for (uint i = 0; i < s; i++)
57  v[i] = m[i] << (31 - i);
58 
59  for (uint i = s; i < L; i++) {
60  v[i] = v[i - s] ^ (v[i - s] >> s);
61 
62  for (uint k = 1; k < s; k++)
63  v[i] ^= (((a >> (s - 1 - k)) & 1) * v[i - k]);
64  }
65  }
66  }
67 }
68 
unsigned int uint
Definition: BLI_sys_types.h:67
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
#define L
static unsigned a[3]
Definition: RandGen.cpp:78
CCL_NAMESPACE_BEGIN void sobol_generate_direction_vectors(uint vectors[][SOBOL_BITS], int dimensions)
Definition: sobol.cpp:31
#define SOBOL_BITS
Definition: sobol.h:11
#define SOBOL_MAX_DIMENSIONS
Definition: sobol.h:12