This commit is contained in:
Gaël committed 2026-10-19 20:59:15 +02:00
commit 87bff164f1
416 files changed
+279512

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
// (needs the Tables buffer `tbl`: its first 512 words are the permutation table)
// 00872560: Gustavson's 3D simplex noise (skew 1/3, unskew 1/6, falloff 0.6, x 32) on the permutation table at the start of Tables (00fdf530 holds the same values)
const ivec3 G3[12] = ivec3[12](ivec3(1,1,0), ivec3(-1,1,0), ivec3(1,-1,0), ivec3(-1,-1,0), ivec3(1,0,1), ivec3(-1,0,1), ivec3(1,0,-1), ivec3(-1,0,-1), ivec3(0,1,1), ivec3(0,-1,1), ivec3(0,1,-1), ivec3(0,-1,-1));
float corner3(int gi, vec3 d) { float t = 0.6 - dot(d, d); if (t < 0.0) return 0.0; t *= t; return t * t * dot(vec3(G3[gi]), d); }
float simplex3(vec3 v) {
const float F3 = 1.0 / 3.0, G = 1.0 / 6.0;
const float s = (v.x + v.y + v.z) * F3;
const ivec3 ijk = ivec3(floor(v + s));
const float t = float(ijk.x + ijk.y + ijk.z) * G;
const vec3 d0 = v - (vec3(ijk) - t);
ivec3 o1, o2;
if (d0.x >= d0.y) { if (d0.y >= d0.z) { o1 = ivec3(1,0,0); o2 = ivec3(1,1,0); } else if (d0.x >= d0.z) { o1 = ivec3(1,0,0); o2 = ivec3(1,0,1); } else { o1 = ivec3(0,0,1); o2 = ivec3(1,0,1); } }
else { if (d0.y < d0.z) { o1 = ivec3(0,0,1); o2 = ivec3(0,1,1); } else if (d0.x < d0.z) { o1 = ivec3(0,1,0); o2 = ivec3(0,1,1); } else { o1 = ivec3(0,1,0); o2 = ivec3(1,1,0); } }
const vec3 d1 = d0 - vec3(o1) + G, d2 = d0 - vec3(o2) + 2.0 * G, d3 = d0 - 1.0 + 3.0 * G;
const int ii = ijk.x & 255, jj = ijk.y & 255, kk = ijk.z & 255;
#define P(n) int(tbl[uint(n)])
const int g0 = P(ii + P(jj + P(kk))) % 12;
const int g1 = P(ii + o1.x + P(jj + o1.y + P(kk + o1.z))) % 12;
const int g2 = P(ii + o2.x + P(jj + o2.y + P(kk + o2.z))) % 12;
const int g3 = P(ii + 1 + P(jj + 1 + P(kk + 1))) % 12;
#undef P
return 32.0 * (corner3(g0, d0) + corner3(g1, d1) + corner3(g2, d2) + corner3(g3, d3));
}