32float snoise3(
float x,
float y,
float z);
33float snoise4(
float x,
float y,
float z,
float w);
35#define FASTFLOOR(x) (((int)(x) <= (x)) ? ((int)x) : (((int)x) - 1))
57__constant
unsigned char perm[512] = { 151, 160, 137, 91, 90, 15,
58 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
59 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
60 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
61 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
62 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
63 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
64 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
65 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
66 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
67 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
68 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
69 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
70 151, 160, 137, 91, 90, 15,
71 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
72 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
73 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
74 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
75 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
76 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
77 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
78 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
79 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
80 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
81 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
82 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180 };
102 float grad = 1.0f + (h & 7);
108float grad2(
int hash,
float x,
float y)
111 float u = h < 4 ? x : y;
112 float v = h < 4 ? y : x;
113 return ((h & 1) ? -u : u) + ((h & 2) ? -2.0f * v : 2.0f * v);
116float grad3(
int hash,
float x,
float y,
float z)
119 float u = h < 8 ? x : y;
120 float v = h < 4 ? y : h == 12 || h == 14 ? x
122 return ((h & 1) ? -u : u) + ((h & 2) ? -v : v);
125float grad4(
int hash,
float x,
float y,
float z,
float t)
128 float u = h < 24 ? x : y;
129 float v = h < 16 ? y : z;
130 float w = h < 8 ? z : t;
131 return ((h & 1) ? -u : u) + ((h & 2) ? -v : v) + ((h & 4) ? -w : w);
138 {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}, {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}, {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}, {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}, {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}, {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}, {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}, {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} };
147 float x1 = x0 - 1.0f;
151 float t0 = 1.0f - x0 * x0;
154 n0 = t0 * t0 *
grad1(
perm[i0 & 0xff], x0);
156 float t1 = 1.0f - x1 * x1;
159 n1 = t1 * t1 *
grad1(
perm[i1 & 0xff], x1);
163 return 0.25f * (n0 + n1);
170#define F2 0.366025403f
171#define G2 0.211324865f
176 float s = (x + y) *
F2;
182 float t = (float)(i + j) *
G2;
206 float x1 = x0 - i1 +
G2;
207 float y1 = y0 - j1 +
G2;
208 float x2 = x0 - 1.0f + 2.0f *
G2;
209 float y2 = y0 - 1.0f + 2.0f *
G2;
216 float t0 = 0.5f - x0 * x0 - y0 * y0;
225 float t1 = 0.5f - x1 * x1 - y1 * y1;
234 float t2 = 0.5f - x2 * x2 - y2 * y2;
245 return 40.0f * (n0 + n1 + n2);
253#define F3 0.333333333f
254#define G3 0.166666667f
256 float n0, n1, n2, n3;
259 float s = (x + y + z) *
F3;
267 float t = (float)(i + j + k) *
G3;
347 float x1 = x0 - i1 +
G3;
348 float y1 = y0 - j1 +
G3;
349 float z1 = z0 - k1 +
G3;
350 float x2 = x0 - i2 + 2.0f *
G3;
351 float y2 = y0 - j2 + 2.0f *
G3;
352 float z2 = z0 - k2 + 2.0f *
G3;
353 float x3 = x0 - 1.0f + 3.0f *
G3;
354 float y3 = y0 - 1.0f + 3.0f *
G3;
355 float z3 = z0 - 1.0f + 3.0f *
G3;
363 float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0;
372 float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1;
381 float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2;
390 float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3;
401 return 72.0f * (n0 + n1 + n2 + n3);
405float snoise4(
float x,
float y,
float z,
float w)
409#define F4 0.309016994f
410#define G4 0.138196601f
412 float n0, n1, n2, n3, n4;
415 float s = (x + y + z + w) *
F4;
425 float t = (i + j + k + l) *
G4;
444 int c1 = (x0 > y0) ? 32 : 0;
445 int c2 = (x0 > z0) ? 16 : 0;
446 int c3 = (y0 > z0) ? 8 : 0;
447 int c4 = (x0 > w0) ? 4 : 0;
448 int c5 = (y0 > w0) ? 2 : 0;
449 int c6 = (z0 > w0) ? 1 : 0;
450 int c = c1 + c2 + c3 + c4 + c5 + c6;
461 i1 =
simplex[c][0] >= 3 ? 1 : 0;
462 j1 =
simplex[c][1] >= 3 ? 1 : 0;
463 k1 =
simplex[c][2] >= 3 ? 1 : 0;
464 l1 =
simplex[c][3] >= 3 ? 1 : 0;
466 i2 =
simplex[c][0] >= 2 ? 1 : 0;
467 j2 =
simplex[c][1] >= 2 ? 1 : 0;
468 k2 =
simplex[c][2] >= 2 ? 1 : 0;
469 l2 =
simplex[c][3] >= 2 ? 1 : 0;
471 i3 =
simplex[c][0] >= 1 ? 1 : 0;
472 j3 =
simplex[c][1] >= 1 ? 1 : 0;
473 k3 =
simplex[c][2] >= 1 ? 1 : 0;
474 l3 =
simplex[c][3] >= 1 ? 1 : 0;
477 float x1 = x0 - i1 +
G4;
478 float y1 = y0 - j1 +
G4;
479 float z1 = z0 - k1 +
G4;
480 float w1 = w0 - l1 +
G4;
481 float x2 = x0 - i2 + 2.0f *
G4;
482 float y2 = y0 - j2 + 2.0f *
G4;
483 float z2 = z0 - k2 + 2.0f *
G4;
484 float w2 = w0 - l2 + 2.0f *
G4;
485 float x3 = x0 - i3 + 3.0f *
G4;
486 float y3 = y0 - j3 + 3.0f *
G4;
487 float z3 = z0 - k3 + 3.0f *
G4;
488 float w3 = w0 - l3 + 3.0f *
G4;
489 float x4 = x0 - 1.0f + 4.0f *
G4;
490 float y4 = y0 - 1.0f + 4.0f *
G4;
491 float z4 = z0 - 1.0f + 4.0f *
G4;
492 float w4 = w0 - 1.0f + 4.0f *
G4;
501 float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
510 float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
519 float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
528 float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
537 float t4 = 0.5f - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
547 return 62.0f * (n0 + n1 + n2 + n3 + n4);
__constant unsigned char simplex[64][4]
float snoise2(float x, float y)
float grad2(int hash, float x, float y)
float snoise4(float x, float y, float z, float w)
float grad3(int hash, float x, float y, float z)
__constant unsigned char perm[512]
float snoise3(float x, float y, float z)
float grad4(int hash, float x, float y, float z, float t)
float grad1(int hash, float x)