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.
- Returns
- unscaled noise value as a signed integer, roughly -18k to 18k
- Parameters
-
x | x-axis coordinate on noise map (1D) |
y | y-axis coordinate on noise map (2D) |
Definition at line 472 of file noise.cpp.
473{
474
477
478
482 uint8_t B =
P(X+1)+Y;
485
486
487 uint16_t u =
x & 0xFFFF;
488 uint16_t v =
y & 0xFFFF;
489
490
491 int16_t xx = (u >> 1) & 0x7FFF;
492 int16_t yy = (v >> 1) & 0x7FFF;
493 uint16_t N = 0x8000L;
494
495 u = EASE16(u); v = EASE16(v);
496
497 int16_t X1 = LERP(
grad16(
P(AA), xx, yy),
grad16(
P(BA), xx - N, yy), u);
498 int16_t X2 = LERP(
grad16(
P(AB), xx, yy-N),
grad16(
P(BB), xx - N, yy - N), u);
499
500 int16_t ans = LERP(X1,X2,v);
501
502 return ans;
503}
#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)
References grad16(), P, x, and y.