31float noise2D(
float x,
float y, uint64_t seed = 0) noexcept {
32 int xi =
static_cast<int>(std::floor(x));
33 int yi =
static_cast<int>(std::floor(y));
38 float v10 =
random2D(xi + 1, yi, seed);
39 float v01 =
random2D(xi, yi + 1, seed);
40 float v11 =
random2D(xi + 1, yi + 1, seed);
54inline float fbm2D(
float x,
float y,
int octaves = 5, uint64_t seed = 0,
float gain = 0.5f,
float lacunarity = 2.0f) noexcept {
56 float amplitude = 1.0f;
57 float frequency = 1.0f;
59 for (
int i = 0; i < octaves; ++i) {
60 value += amplitude *
noise2D(x * frequency, y * frequency, seed + i * 1337);
61 frequency *= lacunarity;
68inline float warp2D(
float x,
float y, uint64_t seed = 0,
float strength = 2.0f) noexcept {
69 float warpX =
noise2D(x * 0.5f, y * 0.5f, seed + 11);
70 float warpY =
noise2D(x * 0.5f + 100.0f, y * 0.5f + 100.0f, seed + 23);
71 return noise2D(x + warpX * strength, y + warpY * strength, seed + 99);
80inline float ridge2D(
float x,
float y,
int octaves = 5,
float gain = 0.5f,
float lacunarity = 2.0f, uint64_t seed = 0) noexcept {
81 auto ridge = [](
float n) {
return 1.0f - std::fabs(n); };
84 float amplitude = 0.5f;
85 float frequency = 1.0f;
87 for (
int i = 0; i < octaves; ++i) {
88 float n = ridge(
noise2D(x * frequency, y * frequency, seed + i * 1000));
89 result += n * amplitude;
90 frequency *= lacunarity;
97inline float rarity2D(
float x,
float y,
float rarity = 0.01f, uint64_t seed = 0) {
100 if (r > rarity)
return 0.0f;
104inline float worley2D(
float x,
float y, uint64_t seed = 0) noexcept {
105 int xi = (int)floor(x);
106 int yi = (int)floor(y);
107 float minDist = 9999.0f;
110 for (
int j = -1; j <= 1; ++j) {
111 for (
int i = -1; i <= 1; ++i) {
117 float fy =
random2D(cx, cy, seed + 1337);
125 float dist = sqrt(dx*dx + dy*dy);
138inline void initPerm(uint8_t* perm, uint64_t seed) {
140 for(
int i=0;i<256;i++) perm[i]=i;
143 for(
int i=255;i>0;i--){
146 int j = int(h % (i+1));
147 std::swap(perm[i], perm[j]);
151 for(
int i=0;i<256;i++) perm[i+256]=perm[i];
154inline float grad(
int hash,
float x,
float y) {
156 float u = h < 4 ? x : y;
157 float v = h < 4 ? y : x;
158 return ((h & 1) ? -u : u) + ((h & 2) ? -2.0f*v : 2.0f*v);
161inline float simplex2D(
float xin,
float yin, uint64_t seed = 0) {
162 static uint8_t perm[512];
163 static bool initialized=
false;
164 if(!initialized){
initPerm(perm, seed); initialized=
true; }
166 const float F2 = 0.5f*(sqrt(3.0f)-1.0f);
167 float s = (xin + yin) * F2;
168 int i = floor(xin + s);
169 int j = floor(yin + s);
170 const float G2 = (3.0f - sqrt(3.0f))/6.0f;
171 float t = (i + j) * G2;
172 float X0 = i - t, Y0 = j - t;
173 float x0 = xin - X0, y0 = yin - Y0;
175 int i1 = (x0 > y0) ? 1 : 0;
176 int j1 = (x0 > y0) ? 0 : 1;
178 float x1 = x0 - i1 + G2;
179 float y1 = y0 - j1 + G2;
180 float x2 = x0 - 1.0f + 2.0f * G2;
181 float y2 = y0 - 1.0f + 2.0f * G2;
188 float t0 = 0.5f - x0*x0 - y0*y0;
189 n0 = (t0<0)?0:pow(t0,4) *
grad(perm[ii+perm[jj]], x0, y0);
191 float t1 = 0.5f - x1*x1 - y1*y1;
192 n1 = (t1<0)?0:pow(t1,4) *
grad(perm[ii+i1+perm[jj+j1]], x1, y1);
194 float t2 = 0.5f - x2*x2 - y2*y2;
195 n2 = (t2<0)?0:pow(t2,4) *
grad(perm[ii+1+perm[jj+1]], x2, y2);
197 return (70.0f * (n0 + n1 + n2)) * 0.5 + 0.5;
float grad(int hash, float x, float y)
Definition Noise.hpp:154
float random2D(int x, int y, uint64_t seed=0) noexcept
Definition Deterministic.hpp:67
float rarity2D(float x, float y, float rarity=0.01f, uint64_t seed=0)
Definition Noise.hpp:97
float simplex2D(float xin, float yin, uint64_t seed=0)
Definition Noise.hpp:161
float warp2D(float x, float y, uint64_t seed=0, float strength=2.0f) noexcept
Definition Noise.hpp:68
float ridge2D(float x, float y, int octaves=5, float gain=0.5f, float lacunarity=2.0f, uint64_t seed=0) noexcept
Ridged Fractal Noise (inverted fBm).
Definition Noise.hpp:80
float worley2D(float x, float y, uint64_t seed=0) noexcept
Definition Noise.hpp:104
constexpr uint64_t GOLDEN_64
Definition Deterministic.hpp:22
void initPerm(uint8_t *perm, uint64_t seed)
Definition Noise.hpp:138
float InterpolateEaseInOut(float a, float b, float t) noexcept
Definition Smoothing.hpp:36
uint64_t mix64(uint64_t x) noexcept
Definition Deterministic.hpp:40
float noise2D(float x, float y, uint64_t seed=0) noexcept
2D deterministic value noise in [-1, 1].
Definition Noise.hpp:31
float fbm2D(float x, float y, int octaves=5, uint64_t seed=0, float gain=0.5f, float lacunarity=2.0f) noexcept
Fractal Brownian Motion (fBm).
Definition Noise.hpp:54