Go to the documentation of this file.
20 #include <smmintrin.h>
31 inline double floorSSE(
double val) {
return _mm_floor_sd(_mm_set_sd(0.0), _mm_set_sd(val))[0]; }
34 return _mm_round_sd(_mm_set_sd(0.0), _mm_set_sd(val), _MM_FROUND_TO_NEAREST_INT)[0];
37 #define floorSSE floor
38 #define roundSSE round
42 double s_curve(
double t) {
return t * t * t * (t * (6 * t - 15) + 10); }
49 for (
int k = 0; k < d; k++) {
50 static const uint32_t M = 1664525, C = 1013904223;
51 seed = seed * M +
index[k] + C;
55 seed ^= (seed << 7) & 0x9d2c5680UL;
56 seed ^= (seed << 15) & 0xefc60000UL;
59 return (((seed & 0xff0000) >> 4) + (seed & 0xff)) & 0xff;
71 for (
int k = 0; k < d; k++) {
72 static const uint32_t M = 1664525, C = 1013904223;
73 u1.i = u1.i * M +
index[k] + C;
77 u1.i ^= (u1.i << 7) & 0x9d2c5680U;
78 u1.i ^= (u1.i << 15) & 0xefc60000U;
82 u2.c[2] =
p[u1.c[1] + u2.c[3]];
83 u2.c[1] =
p[u1.c[2] + u2.c[2]];
84 u2.c[0] =
p[u1.c[3] + u2.c[1]];
90 template <
int d,
class T,
bool periodic>
95 for (
int k = 0; k < d; k++) {
99 index[k] %= period[k];
102 weights[0][k] = X[k] -
f;
103 weights[1][k] = weights[0][k] - 1;
106 const int num = 1 << d;
108 for (
int dummy = 0; dummy < num; dummy++) {
111 for (
int k = 0; k < d; k++) {
112 offset[k] = ((dummy & (1 << k)) != 0);
113 latticeIndex[k] =
index[k] + offset[k];
116 int lookup = hashReduceChar<d>(latticeIndex);
118 for (
int k = 0; k < d; k++) {
120 double weight = weights[offset[k]][k];
121 val += grad * weight;
127 for (
int k = 0; k < d; k++) alphas[k] =
s_curve(weights[0][k]);
129 for (
int newd = d - 1; newd >= 0; newd--) {
130 int newnum = 1 << newd;
131 int k = (d - newd - 1);
133 T beta = T(1) - alphas[k];
134 for (
int dummy = 0; dummy < newnum; dummy++) {
135 int index = dummy * (1 << (d - newd));
136 int otherIndex =
index + (1 << k);
138 vals[
index] = beta * vals[
index] + alpha * vals[otherIndex];
149 template <
int d_in,
int d_out,
class T>
151 uint32_t
index[d_in];
153 for (
int k = 0; k < d_in; k++)
index[k] = uint32_t(
floorSSE(in[k]));
155 out[dim] = hashReduce<d_in>(
index) * (1.0 / 0xffffffffu);
156 if (++dim >= d_out)
break;
157 for (
int k = 0; k < d_in; k++)
index[k] += 1000;
162 template <
int d_in,
int d_out,
class T>
165 for (
int i = 0; i < d_in; i++) P[i] = in[i];
169 out[i] = noiseHelper<d_in, T, false>(P);
170 if (++i >= d_out)
break;
171 for (
int k = 0; k < d_out; k++) P[k] += (T)1000;
176 template <
int d_in,
int d_out,
class T>
177 void PNoise(
const T* in,
const int* period, T* out) {
179 for (
int i = 0; i < d_in; i++) P[i] = in[i];
183 out[i] = noiseHelper<d_in, T, true>(P, period);
184 if (++i >= d_out)
break;
185 for (
int k = 0; k < d_out; k++) P[k] += (T)1000;
191 template <
int d_in,
int d_out,
bool turbulence,
class T>
192 void FBM(
const T* in, T* out,
int octaves, T lacunarity, T gain) {
194 for (
int i = 0; i < d_in; i++) P[i] = in[i];
197 for (
int k = 0; k < d_out; k++) out[k] = 0;
200 T localResult[d_out];
201 Noise<d_in, d_out>(P, localResult);
203 for (
int k = 0; k < d_out; k++) out[k] += fabs(localResult[k]) * scale;
205 for (
int k = 0; k < d_out; k++) out[k] += localResult[k] * scale;
206 if (++octave >= octaves)
break;
208 for (
int k = 0; k < d_in; k++) {
234 int main(
int argc,
char* argv[]) {
237 for (
int i = 0; i < 10000000; i++) {
238 T foo[3] = {.3, .3, .3};
240 sum += SeExpr2::noiseHelper<3, T, false>(foo);
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).  
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
template void FBM< 4, 3, false, double >(const double *, double *, int, double, double)
T noiseHelper(const T *X, const int *period=0)
Noise with d_in dimensional domain, 1 dimensional abcissa.
void CellNoise(const T *in, T *out)
Computes cellular noise (non-interpolated piecewise constant cell random values)
template void FBM< 3, 1, false, double >(const double *, double *, int, double, double)
template void PNoise< 3, 1, double >(const double *, const int *, double *)
void PNoise(const T *in, const int *period, T *out)
Periodic Noise with d_in dimensional domain, d_out dimensional abcissa.
template void FBM< 3, 1, true, double >(const double *, double *, int, double, double)
template void CellNoise< 3, 1, double >(const double *, double *)
template void Noise< 3, 3, double >(const double *, double *)
void Noise(const T *in, T *out)
Noise with d_in dimensional domain, d_out dimensional abcissa.
template void FBM< 3, 3, false, double >(const double *, double *, int, double, double)
template void FBM< 3, 3, true, double >(const double *, double *, int, double, double)
uint32_t hashReduce(uint32_t index[d])
Does a hash reduce to an integer.
void FBM(const T *in, T *out, int octaves, T lacunarity, T gain)
Fractional Brownian Motion. If turbulence is true then turbulence computed.
template void Noise< 1, 1, double >(const double *, double *)
template void Noise< 4, 1, double >(const double *, double *)
template void Noise< 4, 3, double >(const double *, double *)
template void FBM< 4, 1, false, double >(const double *, double *, int, double, double)
template void Noise< 3, 1, double >(const double *, double *)
int main(int argc, char *argv[])
double turbulence(int n, const Vec3d *args)
double s_curve(double t)
This is the Quintic interpolant from Perlin's Improved Noise Paper.
template void Noise< 2, 1, double >(const double *, double *)
template void CellNoise< 3, 3, double >(const double *, double *)
unsigned char hashReduceChar(int index[d])
Does a hash reduce to a character.