9float fade(
float t) {
return t *
t * (3.f - 2.f *
t); }
10float fade5(
float t) {
return t *
t *
t * (
t * (
t * 6.f - 15.f) + 10.f); }
12int wrapIndex(
int i,
int period) {
13 if (period <= 0)
return i;
15 if (
m < 0)
m += period;
19void rotate2(
float&
x,
float&
y) {
21 constexpr float c = 0.87758256189f;
22 constexpr float s = 0.47942553860f;
23 const float nx =
c *
x -
s *
y;
24 const float ny =
s *
x +
c *
y;
34 default:
return std::sqrt(
dx *
dx +
dy *
dy);
47void worleySorted2(
const NoiseField& field,
float x,
float y,
float jitter,
WorleyMetric metric,
float& f1,
float& f2) {
48 jitter = std::clamp(jitter, 0.f, 1.f);
49 const int ix = int(std::floor(
x));
50 const int iy = int(std::floor(
y));
53 for (
int j = -1; j <= 1; ++j) {
54 for (
int i = -1; i <= 1; ++i) {
55 const int cx = ix + i;
56 const int cy = iy + j;
57 const float px = float(
cx) + 0.5f + (
field.hash01(
cx,
cy) - 0.5f) * jitter;
58 const float py = float(
cy) + 0.5f + (
field.hash01(
cx * 7 + 3,
cy * 13 + 5) - 0.5f) * jitter;
59 const float d = metricDist(
x -
px,
y -
py, metric);
70constexpr float kHexFactor = 0.86602540378f;
72float positiveMod(
float v,
float m) {
73 float r = std::fmod(
v,
m);
74 return r < 0.f ?
r +
m :
r;
77void nearestHexCell(
float x,
float y,
float& cellX,
float& cellY) {
79 const float gposX =
x / kHexFactor;
80 const float gposY =
y;
81 float hx = std::floor(gposX);
82 float hy = std::floor(gposY);
83 const float sy = (positiveMod(hx + 1.f, 4.f) >= 2.f) ? 1.f : 0.f;
84 hx += positiveMod(hx, 2.f);
85 hy += positiveMod(hy +
sy, 2.f);
86 const float gdx = gposX - hx;
87 const float gdy = gposY - hy;
88 if (std::fabs(gdx) * (kHexFactor * kHexFactor) + std::fabs(gdy) * 0.5f > 1.f) {
89 hx += (gdx >= 0.f ? 1.f : -1.f) * 2.f;
90 hy += (gdy >= 0.f ? 1.f : -1.f);
96float hexDistLocal(
float px,
float py) {
99 return std::max(
px * kHexFactor +
py * 0.5f,
py) - 1.f;
102float gyroidRaw(
float x,
float y,
float z) {
103 return std::sin(
x) * std::cos(
y) + std::sin(
y) * std::cos(
z) + std::sin(
z) * std::cos(
x);
106float remapSigned01(
float n) {
return std::clamp(
n * 0.5f + 0.5f, 0.f, 1.f); }
114 h ^= uint32_t(ix) * 374761393u;
115 h ^= uint32_t(iy) * 668265263u;
116 h = (
h ^ (
h >> 13)) * 1274126177u;
118 return float(
h & 0x00FFFFFFu) / float(0x00FFFFFFu);
124 const int x0 = int(std::floor(
x));
125 const int y0 = int(std::floor(
y));
126 const float fx = fade(
x -
float(x0));
127 const float fy = fade(
y -
float(y0));
128 const float n00 =
hash01(x0, y0);
129 const float n10 =
hash01(x0 + 1, y0);
130 const float n01 =
hash01(x0, y0 + 1);
131 const float n11 =
hash01(x0 + 1, y0 + 1);
132 const float nx0 = n00 + (n10 - n00) * fx;
133 const float nx1 = n01 + (n11 - n01) * fx;
134 return nx0 + (nx1 - nx0) * fy;
138 const int x0 = int(std::floor(
x));
139 const int y0 = int(std::floor(
y));
140 const float dx =
x - float(x0);
141 const float dy =
y - float(y0);
142 const float fx = fade5(
dx);
143 const float fy = fade5(
dy);
145 auto grad = [&](
int ix,
int iy,
float px,
float py) ->
float {
146 static const float gx[8] = {1.f, -1.f, 1.f, -1.f, 1.f, -1.f, 0.f, 0.f};
147 static const float gy[8] = {1.f, 1.f, -1.f, -1.f, 0.f, 0.f, 1.f, -1.f};
148 const int h = int(
hash01(ix, iy) * 7.999f) & 7;
149 return gx[
h] * (
px - float(ix)) + gy[
h] * (
py -
float(iy));
152 const float n00 = grad(x0, y0,
x,
y);
153 const float n10 = grad(x0 + 1, y0,
x,
y);
154 const float n01 = grad(x0, y0 + 1,
x,
y);
155 const float n11 = grad(x0 + 1, y0 + 1,
x,
y);
156 const float nx0 = n00 + (n10 - n00) * fx;
157 const float nx1 = n01 + (n11 - n01) * fx;
158 const float n = nx0 + (nx1 - nx0) * fy;
159 return std::clamp(
n * 0.5f + 0.5f, 0.f, 1.f);
163 constexpr float K1 = 0.36602540378f;
164 constexpr float K2 = 0.2113248654f;
166 const float s = (
x +
y) * K1;
167 const int i = int(std::floor(
x +
s));
168 const int j = int(std::floor(
y +
s));
169 const float t = float(i + j) * K2;
170 const float x0 =
x - (float(i) -
t);
171 const float y0 =
y - (float(j) -
t);
173 const int i1 = x0 > y0 ? 1 : 0;
174 const int j1 = x0 > y0 ? 0 : 1;
176 const float x1 = x0 - float(
i1) + K2;
177 const float y1 = y0 - float(j1) + K2;
178 const float x2 = x0 - 1.f + 2.f * K2;
179 const float y2 = y0 - 1.f + 2.f * K2;
181 auto gradDot = [&](
int ix,
int iy,
float px,
float py) ->
float {
182 static const float gx[8] = {1.f, -1.f, 1.f, -1.f, 1.f, -1.f, 0.f, 0.f};
183 static const float gy[8] = {1.f, 1.f, -1.f, -1.f, 0.f, 0.f, 1.f, -1.f};
184 const int h = int(
hash01(ix, iy) * 7.999f) & 7;
185 return gx[
h] *
px + gy[
h] *
py;
188 float n0 = 0.f, n1 = 0.f, n2 = 0.f;
189 float t0 = 0.5f - x0 * x0 - y0 * y0;
192 n0 = t0 * t0 * gradDot(i, j, x0, y0);
194 float t1 = 0.5f - x1 * x1 - y1 * y1;
197 n1 = t1 * t1 * gradDot(i +
i1, j + j1, x1, y1);
199 float t2 = 0.5f - x2 * x2 - y2 * y2;
202 n2 = t2 * t2 * gradDot(i + 1, j + 1, x2, y2);
204 return std::clamp(70.f * (n0 + n1 + n2) * 0.5f + 0.5f, 0.f, 1.f);
208 float f1 = 0.f, f2 = 0.f;
209 worleySorted2(*
this,
x,
y, jitter, metric, f1, f2);
214 float f1 = 0.f, f2 = 0.f;
215 worleySorted2(*
this,
x,
y, jitter, metric, f1, f2);
220 return std::clamp(1.f -
worleyF1(
x,
y, jitter, metric), 0.f, 1.f);
224 float f1 = 0.f, f2 = 0.f;
225 worleySorted2(*
this,
x,
y, jitter, metric, f1, f2);
226 return std::max(0.f, f2 - f1);
230 float f1 = 0.f, f2 = 0.f;
231 worleySorted2(*
this,
x,
y, jitter, metric, f1, f2);
232 return std::clamp(1.f - 0.5f * (f1 + f2), 0.f, 1.f);
236 smoothness = std::max(1e-4f, smoothness);
237 jitter = std::clamp(jitter, 0.f, 1.f);
238 const int ix = int(std::floor(
x));
239 const int iy = int(std::floor(
y));
242 for (
int j = -1; j <= 1; ++j) {
243 for (
int i = -1; i <= 1; ++i) {
244 const int cx = ix + i;
245 const int cy = iy + j;
246 const float px = float(
cx) + 0.5f + (
hash01(
cx,
cy) - 0.5f) * jitter;
247 const float py = float(
cy) + 0.5f + (
hash01(
cx * 7 + 3,
cy * 13 + 5) - 0.5f) * jitter;
248 const float dx =
x -
px;
249 const float dy =
y -
py;
251 acc += std::exp(-d2 / (smoothness * smoothness));
254 return std::clamp(1.f - std::exp(-acc), 0.f, 1.f);
258 octaves = std::max(1, octaves);
259 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
260 for (
int i = 0; i < octaves; ++i) {
266 return norm > 0.f ? sum / norm : 0.f;
270 octaves = std::max(1, octaves);
271 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
272 for (
int i = 0; i < octaves; ++i) {
273 const float ox = float(i) * 17.8f;
274 const float oy = float(i) * 23.5f;
280 return norm > 0.f ? sum / norm : 0.f;
284 octaves = std::max(1, octaves);
285 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
286 for (
int i = 0; i < octaves; ++i) {
287 const float ox = float(i) * 13.1f;
288 const float oy = float(i) * 29.7f;
294 return norm > 0.f ? sum / norm : 0.f;
298 octaves = std::max(1, octaves);
299 float sum = 0.f, amp = 1.f, norm = 0.f;
301 for (
int i = 0; i < octaves; ++i) {
311 return norm > 0.f ? sum / norm : 0.f;
315 octaves = std::max(1, octaves);
316 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
317 for (
int i = 0; i < octaves; ++i) {
319 n = 1.f - std::fabs(
n * 2.f - 1.f);
325 return norm > 0.f ? sum / norm : 0.f;
329 octaves = std::max(1, octaves);
330 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
331 for (
int i = 0; i < octaves; ++i) {
332 const float ox = float(i) * 11.3f;
333 const float oy = float(i) * 19.7f;
335 n = 1.f - std::fabs(
n * 2.f - 1.f);
341 return norm > 0.f ? sum / norm : 0.f;
345 octaves = std::max(1, octaves);
346 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
347 for (
int i = 0; i < octaves; ++i) {
348 sum += std::fabs(
valueNoise(
x * freq,
y * freq) * 2.f - 1.f) * amp;
353 return norm > 0.f ? sum / norm : 0.f;
357 octaves = std::max(1, octaves);
358 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
359 for (
int i = 0; i < octaves; ++i) {
360 const float ox = float(i) * 15.4f;
361 const float oy = float(i) * 27.1f;
367 return norm > 0.f ? sum / norm : 0.f;
371 octaves = std::max(1, octaves);
372 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
374 for (
int i = 0; i < octaves; ++i) {
380 px =
x * freq + sum * warpStrength;
381 py =
y * freq + sum * warpStrength;
384 return norm > 0.f ? remapSigned01(sum / norm) : 0.5f;
388 octaves = std::max(1, octaves);
392 float weight = std::clamp(signal, 0.f, 1.f);
395 for (
int i = 1; i < octaves; ++i) {
403 return norm > 0.f ? std::clamp(
result / (norm * (1.f +
offset)), 0.f, 1.f) : 0.f;
409 return std::clamp(
w *
p, 0.f, 1.f);
413 const float wx =
fbm(
x + 19.1f,
y + 7.3f, octaves) - 0.5f;
414 const float wy =
fbm(
x + 5.2f,
y + 31.7f, octaves) - 0.5f;
415 return fbm(
x +
wx * amp,
y +
wy * amp, octaves);
419 const float qx =
fbm(
x,
y, octaves);
420 const float qy =
fbm(
x + 5.2f,
y + 1.3f, octaves);
421 const float rx =
fbm(
x + amp *
qx + 1.7f,
y + amp *
qy + 9.2f, octaves);
422 const float ry =
fbm(
x + amp *
qx + 8.3f,
y + amp *
qy + 2.8f, octaves);
423 return fbm(
x + amp * rx,
y + amp * ry, octaves);
427 eps = std::max(eps, 1e-6f);
433 eps = std::max(eps, 1e-6f);
439 float cx = 0.f,
cy = 0.f;
440 nearestHexCell(
x,
y,
cx,
cy);
441 const float ox =
x -
cx * kHexFactor;
442 const float oy =
y -
cy;
443 return std::fabs(hexDistLocal(
ox,
oy));
447 float cx = 0.f,
cy = 0.f;
448 nearestHexCell(
x,
y,
cx,
cy);
449 return hash01(
int(std::floor(
cx)),
int(std::floor(
cy)));
454 const float band = std::max(
soft, 1e-4f);
456 const float t = std::clamp((
d -
width) / band, 0.f, 1.f);
457 return 1.f - (
t *
t * (3.f - 2.f *
t));
462 const float p = float(
seed) * 0.001f;
463 return remapSigned01(gyroidRaw(
x +
p,
y +
p * 1.3f,
z +
p * 0.7f) / 1.5f);
467 octaves = std::max(1, std::min(octaves, 8));
472 const float ph = float(
seed) * 0.001f;
473 for (
int i = 0; i < octaves; ++i) {
475 result += std::fabs(gyroidRaw((
x + ph) /
a, (
y + ph) /
a, (seedZ + ph) /
a)) *
a;
479 return norm > 0.f ? std::clamp(
result / (norm * 1.5f), 0.f, 1.f) : 0.f;
483 octaves = std::max(1, octaves);
484 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
485 float dx = 0.f,
dy = 0.f;
486 constexpr float kEps = 1e-3f;
487 for (
int i = 0; i < octaves; ++i) {
488 const float px =
x * freq +
dx * warpStrength;
489 const float py =
y * freq +
dy * warpStrength;
500 return norm > 0.f ? remapSigned01(sum / norm) : 0.5f;
505 const int ix = int(std::floor(
x));
506 const int iy = int(std::floor(
y));
507 const float fx =
x - float(ix);
508 const float fy =
y - float(iy);
509 constexpr float kCellVar = 0.8f;
510 constexpr float kDirVar = 0.4f;
513 for (
int j = -1; j <= 1; ++j) {
514 for (
int i = -1; i <= 1; ++i) {
515 const int cx = ix + i;
516 const int cy = iy + j;
518 const float hy = (
hash01(
cx * 3 + 11,
cy * 7 + 5) - 0.5f);
519 const float ox = float(i) - 0.5f;
520 const float oy = float(j) - 0.5f;
521 const float ppx = fx +
ox - hx;
522 const float ppy = fy +
oy - hy;
523 const float d2 = ppx * ppx + ppy * ppy;
524 const float w = std::exp(-d2 * 4.f);
525 float dx = kDirVar * hx + dirX;
526 float dy = kDirVar * hy + dirY;
528 va += std::cos((ppx *
dx + ppy *
dy) * frequency / kCellVar) *
w;
531 return wt > 0.f ? remapSigned01(va / wt) : 0.5f;
535 octaves = std::max(1, std::min(octaves, 8));
536 float sum = 0.f, freq = 1.f, norm = 0.f, amp = 1.f;
538 for (
int i = 0; i < octaves; ++i) {
539 const float n =
gabor(
px * freq,
py * freq, dirX, dirY) * 2.f - 1.f;
540 sum += std::fabs(
n) * amp;
547 return norm > 0.f ? std::clamp(sum / norm, 0.f, 1.f) : 0.f;
551 eps = std::max(eps, 1e-6f);
556 eps = std::max(eps, 1e-6f);
563 return std::sqrt(
dx *
dx +
dy *
dy);
567 levels = std::max(1, levels);
571 const float scaled =
n * float(levels);
572 const float v = std::fabs(std::fmod(scaled + 0.5f, 1.f) - 0.5f);
573 const float t = std::clamp(
v /
width, 0.f, 1.f);
574 return 1.f - (
t *
t * (3.f - 2.f *
t));
578 bands = std::max(1, bands);
580 const float step = 1.f / float(bands);
581 return std::floor(
n *
float(bands)) *
step;
586 channel = ((channel % 3) + 3) % 3;
587 static constexpr float kOx[3] = {0.f, 19.1f, 5.2f};
588 static constexpr float kOy[3] = {0.f, 7.3f, 31.7f};
589 return fbm(
x + kOx[channel],
y + kOy[channel], octaves, lacunarity,
gain);
599 h ^= uint32_t(ix) * 374761393u;
600 h ^= uint32_t(iy) * 668265263u;
601 h ^= uint32_t(iz) * 2246822519u;
602 h = (
h ^ (
h >> 13)) * 1274126177u;
604 return float(
h & 0x00FFFFFFu) / float(0x00FFFFFFu);
610 const int x0 = int(std::floor(
x));
611 const int y0 = int(std::floor(
y));
612 const int z0 = int(std::floor(
z));
613 const float fx = fade(
x -
float(x0));
614 const float fy = fade(
y -
float(y0));
615 const float fz = fade(
z -
float(z0));
617 const float n000 =
hash01(x0, y0, z0);
618 const float n100 =
hash01(x0 + 1, y0, z0);
619 const float n010 =
hash01(x0, y0 + 1, z0);
620 const float n110 =
hash01(x0 + 1, y0 + 1, z0);
621 const float n001 =
hash01(x0, y0, z0 + 1);
622 const float n101 =
hash01(x0 + 1, y0, z0 + 1);
623 const float n011 =
hash01(x0, y0 + 1, z0 + 1);
624 const float n111 =
hash01(x0 + 1, y0 + 1, z0 + 1);
626 const float nx00 = n000 + (n100 - n000) * fx;
627 const float nx10 = n010 + (n110 - n010) * fx;
628 const float nx01 = n001 + (n101 - n001) * fx;
629 const float nx11 = n011 + (n111 - n011) * fx;
630 const float nxy0 = nx00 + (nx10 - nx00) * fy;
631 const float nxy1 = nx01 + (nx11 - nx01) * fy;
632 return nxy0 + (nxy1 - nxy0) * fz;
636 const int x0 = int(std::floor(
x));
637 const int y0 = int(std::floor(
y));
638 const int z0 = int(std::floor(
z));
639 const float dx =
x - float(x0);
640 const float dy =
y - float(y0);
641 const float dz =
z - float(z0);
642 const float fx = fade5(
dx);
643 const float fy = fade5(
dy);
644 const float fz = fade5(
dz);
646 auto grad = [&](
int ix,
int iy,
int iz,
float px,
float py,
float pz) ->
float {
648 static const float g[12][3] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1},
649 {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
650 const int h = int(
hash01(ix, iy, iz) * 11.999f) % 12;
651 return g[
h][0] * (
px - float(ix)) +
g[
h][1] * (
py -
float(iy)) +
g[
h][2] * (
pz -
float(iz));
654 const float n000 = grad(x0, y0, z0,
x,
y,
z);
655 const float n100 = grad(x0 + 1, y0, z0,
x,
y,
z);
656 const float n010 = grad(x0, y0 + 1, z0,
x,
y,
z);
657 const float n110 = grad(x0 + 1, y0 + 1, z0,
x,
y,
z);
658 const float n001 = grad(x0, y0, z0 + 1,
x,
y,
z);
659 const float n101 = grad(x0 + 1, y0, z0 + 1,
x,
y,
z);
660 const float n011 = grad(x0, y0 + 1, z0 + 1,
x,
y,
z);
661 const float n111 = grad(x0 + 1, y0 + 1, z0 + 1,
x,
y,
z);
663 const float nx00 = n000 + (n100 - n000) * fx;
664 const float nx10 = n010 + (n110 - n010) * fx;
665 const float nx01 = n001 + (n101 - n001) * fx;
666 const float nx11 = n011 + (n111 - n011) * fx;
667 const float nxy0 = nx00 + (nx10 - nx00) * fy;
668 const float nxy1 = nx01 + (nx11 - nx01) * fy;
669 const float n = nxy0 + (nxy1 - nxy0) * fz;
670 return std::clamp(
n * 0.5f + 0.5f, 0.f, 1.f);
675 constexpr float F3 = 1.f / 3.f;
676 constexpr float G3 = 1.f / 6.f;
678 const float s = (
x +
y +
z) * F3;
679 const int i = int(std::floor(
x +
s));
680 const int j = int(std::floor(
y +
s));
681 const int k = int(std::floor(
z +
s));
682 const float t = float(i + j + k) * G3;
683 const float x0 =
x - (float(i) -
t);
684 const float y0 =
y - (float(j) -
t);
685 const float z0 =
z - (float(k) -
t);
687 int i1, j1, k1,
i2, j2, k2;
696 }
else if (x0 >= z0) {
719 }
else if (x0 < z0) {
736 const float x1 = x0 - float(
i1) + G3;
737 const float y1 = y0 - float(j1) + G3;
738 const float z1 = z0 - float(k1) + G3;
739 const float x2 = x0 - float(
i2) + 2.f * G3;
740 const float y2 = y0 - float(j2) + 2.f * G3;
741 const float z2 = z0 - float(k2) + 2.f * G3;
742 const float x3 = x0 - 1.f + 3.f * G3;
743 const float y3 = y0 - 1.f + 3.f * G3;
744 const float z3 = z0 - 1.f + 3.f * G3;
746 auto gradDot = [&](
int ix,
int iy,
int iz,
float px,
float py,
float pz) ->
float {
747 static const float g[12][3] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1},
748 {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
749 const int h = int(
hash01(ix, iy, iz) * 11.999f) % 12;
753 auto contrib = [&](
float px,
float py,
float pz,
int ix,
int iy,
int iz) ->
float {
755 if (
t < 0.f)
return 0.f;
757 return t *
t * gradDot(ix, iy, iz,
px,
py,
pz);
760 const float n = 32.f * (contrib(x0, y0, z0, i, j, k) + contrib(x1, y1, z1, i +
i1, j + j1, k + k1) +
761 contrib(x2, y2, z2, i +
i2, j + j2, k + k2) + contrib(x3, y3, z3, i + 1, j + 1, k + 1));
762 return std::clamp(
n * 0.5f + 0.5f, 0.f, 1.f);
766 jitter = std::clamp(jitter, 0.f, 1.f);
767 const int ix = int(std::floor(
x));
768 const int iy = int(std::floor(
y));
769 const int iz = int(std::floor(
z));
771 for (
int k = -1; k <= 1; ++k) {
772 for (
int j = -1; j <= 1; ++j) {
773 for (
int i = -1; i <= 1; ++i) {
774 const int cx = ix + i;
775 const int cy = iy + j;
776 const int cz = iz + k;
777 const float px = float(
cx) + 0.5f + (
hash01(
cx,
cy, cz) - 0.5f) * jitter;
778 const float py = float(
cy) + 0.5f + (
hash01(
cx + 17,
cy + 3, cz + 5) - 0.5f) * jitter;
779 const float pz = float(cz) + 0.5f + (
hash01(
cx + 7,
cy + 13, cz + 19) - 0.5f) * jitter;
780 f1 = std::min(f1, metricDist3(
x -
px,
y -
py,
z -
pz, metric));
788 return std::clamp(1.f -
worleyF1(
x,
y,
z, jitter, metric), 0.f, 1.f);
792 octaves = std::max(1, octaves);
793 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
794 for (
int i = 0; i < octaves; ++i) {
800 return norm > 0.f ? sum / norm : 0.f;
804 octaves = std::max(1, octaves);
805 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
806 for (
int i = 0; i < octaves; ++i) {
807 sum +=
perlinNoise(
x * freq +
float(i) * 17.8f,
y * freq +
float(i) * 23.5f,
z * freq +
float(i) * 11.1f) * amp;
812 return norm > 0.f ? sum / norm : 0.f;
816 octaves = std::max(1, octaves);
817 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
818 for (
int i = 0; i < octaves; ++i) {
820 n = 1.f - std::fabs(
n * 2.f - 1.f);
826 return norm > 0.f ? sum / norm : 0.f;
830 octaves = std::max(1, octaves);
831 float sum = 0.f, amp = 1.f, norm = 0.f, freq = 1.f;
832 for (
int i = 0; i < octaves; ++i) {
833 sum += std::fabs(
valueNoise(
x * freq,
y * freq,
z * freq) * 2.f - 1.f) * amp;
838 return norm > 0.f ? sum / norm : 0.f;
842 const float p = float(
seed) * 0.001f;
843 return remapSigned01(gyroidRaw(
x +
p,
y +
p * 1.3f,
z +
p * 0.7f) / 1.5f);
847 octaves = std::max(1, std::min(octaves, 8));
852 const float ph = float(
seed) * 0.001f;
853 for (
int i = 0; i < octaves; ++i) {
855 result += std::fabs(gyroidRaw((
x + ph) /
a, (
y + ph) /
a, (seedZ + ph) /
a)) *
a;
859 return norm > 0.f ? std::clamp(
result / (norm * 1.5f), 0.f, 1.f) : 0.f;
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
WorleyMetric
Distance metric for Worley / cellular noise.
float whiteNoise(int ix, int iy, int iz) const
float valueNoise(float x, float y, float z) const
float fbmPerlin(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
float worleyF1(float x, float y, float z, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
float billow(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
float ridged(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
float simplexNoise(float x, float y, float z) const
float fbm(float x, float y, float z, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
float gyroid(float x, float y, float z) const
float hash01(int ix, int iy, int iz) const
float gyroidFbm(float x, float y, float z, int octaves=4) const
float perlinWorley(float x, float y, float z, int octaves=3, float jitter=1.f) const
float worleyNoise(float x, float y, float z, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
float perlinNoise(float x, float y, float z) const
float hexValue(float x, float y) const
Hash of the nearest hex cell, in [0, 1].
float fbm(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Value-noise fBm.
float worleySmooth(float x, float y, float smoothness=0.25f, float jitter=1.f) const
Smooth-min Worley (metaball / soft cellular).
float gyroidFbm(float x, float y, float z, int octaves=4) const
Absolute-gyroid fBm (noisecreater gyroid fbm), remapped to [0, 1].
float worleyCombine(float x, float y, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
(F1 + F2) * 0.5 remapped via clamp(1 - d, 0, 1).
float gyroid(float x, float y, float z) const
Minimal gyroid field at (x, y, z): dot(sin(p), cos(p.yzx)), remapped to [0, 1].
float worleyNoise(float x, float y, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
Texture-friendly Worley: clamp(1 - F1, 0, 1). Matches NoiseCreator's 1 - minDist cellular look.
float billow(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Billow / turbulence (absolute value-noise fBm), remapped to [0, 1]. Matches noisecreater SampleNoiseB...
float valueDy(float x, float y, float eps=1e-3f) const
∂/∂y of value noise via central differences.
float isoLine(float x, float y, int levels=8, float width=0.04f) const
Contour / isoline mask of value noise in [0, 1] (1 on lines).
float valueSlope(float x, float y, float eps=1e-3f) const
Gradient magnitude of value noise.
float simplexNoise(float x, float y) const
2D Simplex noise remapped to [0, 1]. Same family as noisecreater SampleNoiseA (Ashima-style corners +...
float fbmSimplex(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Simplex fBm with uncorrelated octave offsets.
float curlNoiseY(float x, float y, float eps=1e-3f) const
Divergence-free curl Y of value-noise potential (finite differences).
float fbmColor(float x, float y, int channel, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Decorrelated fBm channel for RGB-style color noise (channel 0/1/2). Same shape as fbm with fixed per-...
float worleyF2(float x, float y, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
Worley F2 (second-nearest) distance.
float gabor(float x, float y, float dirX=0.f, float dirY=0.f, float frequency=6.2831853f) const
Gabor / Voronoi-mix wavelet (noisecreater gavoronoi 3×3), remapped to [0, 1].
float valueDx(float x, float y, float eps=1e-3f) const
∂/∂x of value noise via central differences (slope / erosion helper). Not remapped to [0,...
float ridged(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Ridged multifractal on value noise.
float jordan(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f, float warpStrength=0.35f) const
Musgrave Jordan turbulence: warp by value-noise derivatives. Completes the Swiss / Hybrid / Jordan Mu...
float gaborFbm(float x, float y, int octaves=4, float dirX=0.f, float dirY=0.f) const
Absolute-Gabor fBm remapped to [0, 1] (noisecreater Gabor swirl layers).
float whiteNoise(int ix, int iy) const
White noise at integer lattice point (alias of hash01).
float banding(float x, float y, int bands=5) const
Quantized banding of value noise in [0, 1].
float fbmPerlin(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Perlin fBm with uncorrelated octave offsets.
float warp(float x, float y, float amp, int octaves=3) const
Single-pass domain warp of value fBm.
float hexEdge(float x, float y, float width=0.05f, float soft=0.02f) const
Hex edge line mask in [0, 1] (1 on edge). Matches noisecreater hexNoise edge band.
float perlinWorley(float x, float y, int octaves=3, float jitter=1.f) const
Perlin–Worley hybrid for cloud / soft cellular shapes. Result is worleyNoise * fbmPerlin (NoiseCreato...
float worleyEdge(float x, float y, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
Worley F2 - F1 edge distance (cell borders).
float hybrid(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f, float offset=0.7f) const
Musgrave hybrid multifractal.
float hexDistance(float x, float y) const
Distance to nearest hex edge (noisecreater hexDist field), typically [0, ~1]. Pointy-top lattice; sca...
float billowPerlin(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Billow built from Perlin octaves.
float warpDeep(float x, float y, float amp, int octaves=3) const
Two-pass iq-style domain warp (q then r), then sample fBm. Matches noisecreater DomainWarp / Smoke ne...
float hash01(int ix, int iy) const
Lattice hash mapped to [0, 1].
float perlinNoise(float x, float y) const
Classic 2D Perlin gradient noise, remapped to [0, 1].
float swiss(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f, float warpStrength=0.15f) const
Musgrave Swiss turbulence: each octave warps by the running sum. Good for eroded / alpine terrain....
float ridgedPerlin(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Ridged multifractal on Perlin.
float worleyF1(float x, float y, float jitter=1.f, WorleyMetric metric=WorleyMetric::Euclidean) const
Worley / cellular F1 distance (cell size 1).
float curlNoiseX(float x, float y, float eps=1e-3f) const
Divergence-free curl X of value-noise potential (finite differences). Pair with curlNoiseY for partic...
float fbmRotated(float x, float y, int octaves=4, float lacunarity=2.f, float gain=0.5f) const
Rotated value-noise fBm (axial-bias reduction). Each octave applies a fixed 2D rotation like noisecre...
float valueNoise(float x, float y) const
Smooth value noise.