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.
319{
320
321 uint8_t X = (
x>>16)&0xFF;
322 uint8_t Y = (
y>>16)&0xFF;
323 uint8_t Z = (
z>>16)&0xFF;
324
325
328 uint8_t AB =
P(A+1)+Z;
329 uint8_t B =
P(X+1)+Y;
330 uint8_t BA =
P(B) + Z;
331 uint8_t BB =
P(B+1)+Z;
332
333
334 uint16_t u =
x & 0xFFFF;
335 uint16_t v =
y & 0xFFFF;
336 uint16_t w =
z & 0xFFFF;
337
338
339 int16_t xx = (u >> 1) & 0x7FFF;
340 int16_t yy = (v >> 1) & 0x7FFF;
341 int16_t zz = (w >> 1) & 0x7FFF;
342 uint16_t N = 0x8000L;
343
344 u = EASE16(u); v = EASE16(v); w = EASE16(w);
345
346
347
348 int16_t X1 = LERP(
grad16(
P(AA), xx, yy, zz),
grad16(
P(BA), xx - N, yy, zz), u);
349 int16_t X2 = LERP(
grad16(
P(AB), xx, yy-N, zz),
grad16(
P(BB), xx - N, yy - N, zz), u);
350 int16_t X3 = LERP(
grad16(
P(AA+1), xx, yy, zz-N),
grad16(
P(BA+1), xx - N, yy, zz-N), u);
351 int16_t X4 = LERP(
grad16(
P(AB+1), xx, yy-N, zz-N),
grad16(
P(BB+1), xx - N, yy - N, zz - N), u);
352
353 int16_t Y1 = LERP(X1,X2,v);
354 int16_t Y2 = LERP(X3,X4,v);
355
356 int16_t ans = LERP(Y1,Y2,w);
357
358 return ans;
359}
#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)