54#define OFNOISE_FASTFLOOR(x) ( ((x)>0) ? ((int)x) : (((int)x)-1) )
79unsigned char perm[512] = {151,160,137,91,90,15,
80 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
81 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
82 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
83 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
84 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
85 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
86 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
87 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
88 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
89 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
90 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
91 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
93 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
94 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
95 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
96 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
97 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
98 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
99 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
100 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
101 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
102 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
103 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
104 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
125inline float grad1(
int hash,
float x ) {
127 float grad = 1.0f + (h & 7);
128 if (h&8) grad = -grad;
132inline float grad2(
int hash,
float x,
float y ) {
134 float u = h<4 ? x : y;
135 float v = h<4 ? y : x;
136 return ((h&1)? -u : u) + ((h&2)? -2.0f*v : 2.0f*v);
139inline float grad3(
int hash,
float x,
float y ,
float z ) {
141 float u = h<8 ? x : y;
142 float v = h<4 ? y : h==12||h==14 ? x : z;
143 return ((h&1)? -u : u) + ((h&2)? -v : v);
146inline float grad4(
int hash,
float x,
float y,
float z,
float t ) {
148 float u = h<24 ? x : y;
149 float v = h<16 ? y : z;
150 float w = h<8 ? z : t;
151 return ((h&1)? -u : u) + ((h&2)? -v : v) + ((h&4)? -w : w);
158 unsigned char simplex[64][4] = {
159 {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
160 {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
161 {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
162 {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
163 {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
164 {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
165 {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
166 {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}};
174 float x1 = x0 - 1.0f;
175 float t1 = 1.0f - x1*x1;
178 float t0 = 1.0f - x0*x0;
181 n0 = t0 * t0 *
grad1(perm[i0 & 0xff], x0);
185 n1 = t1 * t1 *
grad1(perm[i1 & 0xff], x1);
189 return 0.25f * (n0 + n1);
195 constexpr float F2 = 0.366025403f;
196 constexpr float G2 = 0.211324865f;
207 float t = (float)(i+j)*G2;
213 float x1, y1, x2, y2;
220 if(x0>y0) {i1=1; j1=0;}
229 x2 = x0 - 1.0f + 2.0f * G2;
230 y2 = y0 - 1.0f + 2.0f * G2;
237 t0 = 0.5f - x0*x0-y0*y0;
238 if(t0 < 0.0f) n0 = 0.0f;
241 n0 = t0 * t0 *
grad2(perm[ii+perm[jj]], x0, y0);
244 t1 = 0.5f - x1*x1-y1*y1;
245 if(t1 < 0.0f) n1 = 0.0f;
248 n1 = t1 * t1 *
grad2(perm[ii+i1+perm[jj+j1]], x1, y1);
251 t2 = 0.5f - x2*x2-y2*y2;
252 if(t2 < 0.0f) n2 = 0.0f;
255 n2 = t2 * t2 *
grad2(perm[ii+1+perm[jj+1]], x2, y2);
260 return 40.0f * (n0 + n1 + n2);
267 constexpr float F3 = 0.333333333f;
268 constexpr float G3 = 0.166666667f;
270 float n0, n1, n2, n3;
273 float s = (x+y+z)*F3;
281 float t = (float)(i+j+k)*G3;
289 float x1, y1, z1, x2, y2, z2, x3, y3, z3;
291 float t0, t1, t2, t3;
301 { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; }
302 else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; }
303 else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; }
306 if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; }
307 else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; }
308 else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; }
319 x2 = x0 - i2 + 2.0f*G3;
320 y2 = y0 - j2 + 2.0f*G3;
321 z2 = z0 - k2 + 2.0f*G3;
322 x3 = x0 - 1.0f + 3.0f*G3;
323 y3 = y0 - 1.0f + 3.0f*G3;
324 z3 = z0 - 1.0f + 3.0f*G3;
332 t0 = 0.6f - x0*x0 - y0*y0 - z0*z0;
333 if(t0 < 0.0f) n0 = 0.0f;
336 n0 = t0 * t0 *
grad3(perm[ii+perm[jj+perm[kk]]], x0, y0, z0);
339 t1 = 0.6f - x1*x1 - y1*y1 - z1*z1;
340 if(t1 < 0.0f) n1 = 0.0f;
343 n1 = t1 * t1 *
grad3(perm[ii+i1+perm[jj+j1+perm[kk+k1]]], x1, y1, z1);
346 t2 = 0.6f - x2*x2 - y2*y2 - z2*z2;
347 if(t2 < 0.0f) n2 = 0.0f;
350 n2 = t2 * t2 *
grad3(perm[ii+i2+perm[jj+j2+perm[kk+k2]]], x2, y2, z2);
353 t3 = 0.6f - x3*x3 - y3*y3 - z3*z3;
354 if(t3<0.0f) n3 = 0.0f;
357 n3 = t3 * t3 *
grad3(perm[ii+1+perm[jj+1+perm[kk+1]]], x3, y3, z3);
362 return 32.0f * (n0 + n1 + n2 + n3);
369 constexpr float F4 = 0.309016994f;
370 constexpr float G4 = 0.138196601f;
372 float n0, n1, n2, n3, n4;
375 float s = (x + y + z + w) * F4;
385 float t = (i + j + k + l) * G4;
404 int c1 = (x0 > y0) ? 32 : 0;
405 int c2 = (x0 > z0) ? 16 : 0;
406 int c3 = (y0 > z0) ? 8 : 0;
407 int c4 = (x0 > w0) ? 4 : 0;
408 int c5 = (y0 > w0) ? 2 : 0;
409 int c6 = (z0 > w0) ? 1 : 0;
410 int c = c1 + c2 + c3 + c4 + c5 + c6;
416 float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
418 float t0, t1, t2, t3, t4;
425 i1 = simplex[
c][0]>=3 ? 1 : 0;
426 j1 = simplex[
c][1]>=3 ? 1 : 0;
427 k1 = simplex[
c][2]>=3 ? 1 : 0;
428 l1 = simplex[
c][3]>=3 ? 1 : 0;
430 i2 = simplex[
c][0]>=2 ? 1 : 0;
431 j2 = simplex[
c][1]>=2 ? 1 : 0;
432 k2 = simplex[
c][2]>=2 ? 1 : 0;
433 l2 = simplex[
c][3]>=2 ? 1 : 0;
435 i3 = simplex[
c][0]>=1 ? 1 : 0;
436 j3 = simplex[
c][1]>=1 ? 1 : 0;
437 k3 = simplex[
c][2]>=1 ? 1 : 0;
438 l3 = simplex[
c][3]>=1 ? 1 : 0;
445 x2 = x0 - i2 + 2.0f*G4;
446 y2 = y0 - j2 + 2.0f*G4;
447 z2 = z0 - k2 + 2.0f*G4;
448 w2 = w0 - l2 + 2.0f*G4;
449 x3 = x0 - i3 + 3.0f*G4;
450 y3 = y0 - j3 + 3.0f*G4;
451 z3 = z0 - k3 + 3.0f*G4;
452 w3 = w0 - l3 + 3.0f*G4;
453 x4 = x0 - 1.0f + 4.0f*G4;
454 y4 = y0 - 1.0f + 4.0f*G4;
455 z4 = z0 - 1.0f + 4.0f*G4;
456 w4 = w0 - 1.0f + 4.0f*G4;
465 t0 = 0.6f - x0*x0 - y0*y0 - z0*z0 - w0*w0;
466 if(t0 < 0.0f) n0 = 0.0f;
469 n0 = t0 * t0 *
grad4(perm[ii+perm[jj+perm[kk+perm[ll]]]], x0, y0, z0, w0);
472 t1 = 0.6f - x1*x1 - y1*y1 - z1*z1 - w1*w1;
473 if(t1 < 0.0f) n1 = 0.0f;
476 n1 = t1 * t1 *
grad4(perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]], x1, y1, z1, w1);
479 t2 = 0.6f - x2*x2 - y2*y2 - z2*z2 - w2*w2;
480 if(t2 < 0.0f) n2 = 0.0f;
483 n2 = t2 * t2 *
grad4(perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]], x2, y2, z2, w2);
486 t3 = 0.6f - x3*x3 - y3*y3 - z3*z3 - w3*w3;
487 if(t3 < 0.0f) n3 = 0.0f;
490 n3 = t3 * t3 *
grad4(perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]], x3, y3, z3, w3);
493 t4 = 0.6f - x4*x4 - y4*y4 - z4*z4 - w4*w4;
494 if(t4 < 0.0f) n4 = 0.0f;
497 n4 = t4 * t4 *
grad4(perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]], x4, y4, z4, w4);
501 return 27.0f * (n0 + n1 + n2 + n3 + n4);
float _slang_library_noise1(float x)
Definition ofNoise.h:169
float _slang_library_noise2(float x, float y)
Definition ofNoise.h:193
#define OFNOISE_FASTFLOOR(x)
Definition ofNoise.h:54
float _slang_library_noise4(float x, float y, float z, float w)
Definition ofNoise.h:366
float grad2(int hash, float x, float y)
Definition ofNoise.h:132
float _slang_library_noise3(float x, float y, float z)
Definition ofNoise.h:264
float grad3(int hash, float x, float y, float z)
Definition ofNoise.h:139
float grad4(int hash, float x, float y, float z, float t)
Definition ofNoise.h:146
float grad1(int hash, float x)
Definition ofNoise.h:125