29 #ifndef NVBLASTEXTAUTHORINGPERLINNOISE_H 30 #define NVBLASTEXTAUTHORINGPERLINNOISE_H 37 #define PERLIN_NOISE_SAMPLE_TABLE 512 49 NV_INLINE float at3(
const float& rx,
const float& ry,
const float& rz,
const PxVec3 q)
51 return rx * q[0] + ry * q[1] + rz * q[2];
54 NV_INLINE float fade(
float t) {
return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f); }
56 NV_INLINE float lerp(
float t,
float a,
float b) {
return a + t * (b - a); }
58 NV_INLINE void setup(
int i, PxVec3 point,
float& t,
int& b0,
int& b1,
float& r0,
float& r1)
60 t = point[i] + (0x1000);
70 int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
71 float rx0, rx1, ry0, ry1, rz0, rz1, sy, sz, a, b, c, d, t, u, v;
75 setup(0, point, t, bx0, bx1, rx0, rx1);
76 setup(1, point, t, by0, by1, ry0, ry1);
77 setup(2, point, t, bz0, bz1, rz0, rz1);
91 q = g[b00 + bz0]; u =
at3(rx0, ry0, rz0, q);
92 q = g[b10 + bz0]; v =
at3(rx1, ry0, rz0, q);
95 q = g[b01 + bz0]; u =
at3(rx0, ry1, rz0, q);
96 q = g[b11 + bz0]; v =
at3(rx1, ry1, rz0, q);
101 q = g[b00 + bz1]; u =
at3(rx0, ry0, rz1, q);
102 q = g[b10 + bz1]; v =
at3(rx1, ry0, rz1, q);
105 q = g[b01 + bz1]; u =
at3(rx0, ry1, rz1, q);
106 q = g[b11 + bz1]; v =
at3(rx1, ry1, rz1, q);
111 return lerp(sz, c, d);
129 mFrequency(frequency),
130 mAmplitude(amplitude),
142 void reset(
int octaves = 1,
float frequency = 1.f,
float amplitude = 1.f)
145 mFrequency = frequency;
146 mAmplitude = amplitude;
155 return perlinNoise(point);
161 float perlinNoise(physx::PxVec3 point)
166 const int octaves = mOctaves;
167 const float frequency = mFrequency;
168 float amplitude = mAmplitude;
173 for (
int i = 0; i < octaves; ++i)
196 for (j = 0; j < 3; ++j)
211 p[(unsigned)PERLIN_NOISE_SAMPLE_TABLE + i] = p[i];
212 for (j = 0; j < 3; ++j)
213 g[(
unsigned)PERLIN_NOISE_SAMPLE_TABLE + i][j] = g[i][j];
243 static const int X_NOISE_GEN = 1619;
244 static const int Y_NOISE_GEN = 31337;
245 static const int Z_NOISE_GEN = 6971;
246 static const int W_NOISE_GEN = 1999;
247 static const int SEED_NOISE_GEN = 1013;
248 static const int SHIFT_NOISE_GEN = 8;
252 return (x >= 0) ? (int)x : (
int)(x - 1);
267 SimplexNoise(
float ampl,
float freq, int32_t octaves, int32_t seed) : mOctaves(octaves), mAmplitude(ampl), mFrequency(freq), mSeed(seed) {};
280 physx::PxVec4
eval4D(
float x,
float y,
float z,
float w,
int seed)
283 const float F4 = (physx::PxSqrt(5.0f) - 1.0f) / 4.0f;
284 const float G4 = (5.0f - physx::PxSqrt(5.0f)) / 20.0f;
286 float s = (x + y + z +
w) * F4;
287 int ix = fastfloor(x + s);
288 int iy = fastfloor(y + s);
289 int iz = fastfloor(z + s);
290 int iw = fastfloor(w + s);
291 float tu = (ix + iy + iz + iw) * G4;
293 float x0 = x - (ix - tu);
294 float y0 = y - (iy - tu);
295 float z0 = z - (iz - tu);
296 float w0 = w - (iw - tu);
298 int c = (x0 > y0) ? (1 << 0) : (1 << 2);
299 c += (x0 > z0) ? (1 << 0) : (1 << 4);
300 c += (x0 > w0) ? (1 << 0) : (1 << 6);
301 c += (y0 > z0) ? (1 << 2) : (1 << 4);
302 c += (y0 > w0) ? (1 << 2) : (1 << 6);
303 c += (z0 > w0) ? (1 << 4) : (1 << 6);
309 for (
int p = 4; p >= 0; --p)
311 int ixp = ((c >> 0) & 3) >= p ? 1 : 0;
312 int iyp = ((c >> 2) & 3) >= p ? 1 : 0;
313 int izp = ((c >> 4) & 3) >= p ? 1 : 0;
314 int iwp = ((c >> 6) & 3) >= p ? 1 : 0;
316 float xp = x0 - ixp + (4 - p) * G4;
317 float yp = y0 - iyp + (4 - p) * G4;
318 float zp = z0 - izp + (4 - p) * G4;
319 float wp = w0 - iwp + (4 - p) * G4;
321 float t = 0.6f - xp * xp - yp * yp - zp * zp - wp * wp;
325 int gradIndex = int((
326 X_NOISE_GEN * (ix + ixp)
327 + Y_NOISE_GEN * (iy + iyp)
328 + Z_NOISE_GEN * (iz + izp)
329 + W_NOISE_GEN * (iw + iwp)
330 + SEED_NOISE_GEN * seed)
332 gradIndex ^= (gradIndex >> SHIFT_NOISE_GEN);
337 const int h = gradIndex;
338 const int hs = 2 - (h >> 4);
339 const int h1 = (h >> 3);
340 g.x = (h1 == 0) ? 0.0f : ((h & 4) ? -1.0f : 1.0f);
341 g.y = (h1 == 1) ? 0.0f : ((h & (hs << 1)) ? -1.0f : 1.0f);
342 g.z = (h1 == 2) ? 0.0f : ((h & hs) ? -1.0f : 1.0f);
343 g.w = (h1 == 3) ? 0.0f : ((h & 1) ? -1.0f : 1.0f);
345 float gdot = (g.x * xp + g.y * yp + g.z * zp + g.w * wp);
351 float dt4gdot = 8 * t3 * gdot;
353 res.x += t4 * g.x - dt4gdot * xp;
354 res.y += t4 * g.y - dt4gdot * yp;
355 res.z += t4 * g.z - dt4gdot * zp;
374 for (int32_t i = 1; i <= mOctaves; ++i)
376 result += eval4D(p.x * i, p.y * i, p.z * i, i * 5.0f, mSeed).w * alpha;
379 return result * mAmplitude;
SimplexNoise(float ampl, float freq, int32_t octaves, int32_t seed)
Definition: NvBlastExtAuthoringPerlinNoise.h:267
physx::PxVec4 eval4D(float x, float y, float z, float w, int seed)
Definition: NvBlastExtAuthoringPerlinNoise.h:280
SIMD_FORCE_INLINE const btScalar & x() const
Return the x value.
Definition: btVector3.h:275
float sample(physx::PxVec3 p)
Definition: NvBlastExtAuthoringPerlinNoise.h:369
NV_INLINE void setup(int i, PxVec3 point, float &t, int &b0, int &b1, float &r0, float &r1)
Definition: NvBlastExtAuthoringPerlinNoise.h:58
Definition: NvBlastExtAuthoringFractureTool.h:66
virtual float getRandomValue()=0
#define PERLIN_NOISE_SAMPLE_TABLE
Definition: NvBlastExtAuthoringPerlinNoise.h:37
NV_INLINE float noiseSample(PxVec3 point, int *p, PxVec3 *g)
Definition: NvBlastExtAuthoringPerlinNoise.h:68
NV_INLINE float lerp(float t, float a, float b)
Definition: NvBlastExtAuthoringPerlinNoise.h:56
NV_INLINE float at3(const float &rx, const float &ry, const float &rz, const PxVec3 q)
Definition: NvBlastExtAuthoringPerlinNoise.h:49
SIMD_FORCE_INLINE const btScalar & y() const
Return the y value.
Definition: btVector3.h:277
void reset(int octaves=1, float frequency=1.f, float amplitude=1.f)
Definition: NvBlastExtAuthoringPerlinNoise.h:142
NV_INLINE float fade(float t)
Definition: NvBlastExtAuthoringPerlinNoise.h:54
#define NV_INLINE
Definition: NvPreprocessor.h:350
Definition: NvBlastExtAuthoringPerlinNoise.h:117
PerlinNoise(Nv::Blast::RandomGeneratorBase *rnd, int octaves=1, float frequency=1., float amplitude=1.)
Definition: NvBlastExtAuthoringPerlinNoise.h:126
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition: btVector3.h:279
Definition: NvBlastExtAuthoringPerlinNoise.h:235
float sample(const physx::PxVec3 &point)
Definition: NvBlastExtAuthoringPerlinNoise.h:153
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btVector3.h:281
Definition: NvBlastArray.h:37