32 bit, fixed point implementation of simplex noise functions.
The inputs are 20.12 fixed-point value. The result covers the full range of a uint16_t averaging around 32768.
Definition at line 102 of file simplex.cpp.
102 {
103 uint32_t i0 =
x >> 12;
104 uint32_t i1 = i0 + 1;
105 int32_t x0 =
x & 0xfff;
106 int32_t x1 = x0 - 0x1000;
107
108 int32_t t0 = 0x8000 - ((x0*x0)>>9);
109 t0 = (t0 * t0) >> 15;
110 t0 = (t0 * t0) >> 15;
111 int32_t n0 = (t0 *
grad(
P(i0&0xff), x0)) >> 12;
112
113 int32_t t1 = 0x8000 - ((x1*x1)>>9);
114 t1 = (t1 * t1) >> 15;
115 t1 = (t1 * t1) >> 15;
116 int32_t n1 = (t1 *
grad(
P(i1&0xff), x1)) >> 12;
117
118 int32_t n = n0 + n1;
119 n += 2503;
120 n = (n * 26694) >> 16;
121 return uint16_t(n) + 0x8000;
122}
static int32_t grad(uint8_t hash, int32_t x)
References grad(), P, and x.