16-bit, fixed point implementation of Perlin's noise without scaling.
Coordinates are 16.16 fixed point values, 32 bit integers with integral coordinates in the high 16-bits and fractional in the low 16-bits.
345{
346
347 uint8_t X = (
x>>16)&0xFF;
348 uint8_t Y = (
y>>16)&0xFF;
349 uint8_t Z = (
z>>16)&0xFF;
350
351
354 uint8_t AB =
P(A+1)+Z;
355 uint8_t B =
P(X+1)+Y;
356 uint8_t BA =
P(B) + Z;
357 uint8_t BB =
P(B+1)+Z;
358
359
360 uint16_t u =
x & 0xFFFF;
361 uint16_t v =
y & 0xFFFF;
362 uint16_t w =
z & 0xFFFF;
363
364
365 int16_t xx = (u >> 1) & 0x7FFF;
366 int16_t yy = (v >> 1) & 0x7FFF;
367 int16_t zz = (w >> 1) & 0x7FFF;
368 uint16_t N = 0x8000L;
369
370 u = EASE16(u); v = EASE16(v); w = EASE16(w);
371
372
373
374 int16_t X1 = LERP(
grad16(
P(AA), xx, yy, zz),
grad16(
P(BA), xx - N, yy, zz), u);
375 int16_t X2 = LERP(
grad16(
P(AB), xx, yy-N, zz),
grad16(
P(BB), xx - N, yy - N, zz), u);
376 int16_t X3 = LERP(
grad16(
P(AA+1), xx, yy, zz-N),
grad16(
P(BA+1), xx - N, yy, zz-N), u);
377 int16_t X4 = LERP(
grad16(
P(AB+1), xx, yy-N, zz-N),
grad16(
P(BB+1), xx - N, yy - N, zz - N), u);
378
379 int16_t Y1 = LERP(X1,X2,v);
380 int16_t Y2 = LERP(X3,X4,v);
381
382 int16_t ans = LERP(Y1,Y2,w);
383
384 return ans;
385}
#define P(x)
Reads a single byte from the p array.
static int16_t grad16(uint8_t hash, int16_t x, int16_t y, int16_t z)