Ejemplo n.º 1
0
        /**
         * Generate overlapping cubic lattices for 3D Re-oriented BCC noise.
         * Lookup table implementation inspired by DigitalShadow.
         * It was actually faster to narrow down the points in the loop itself,
         * than to build up the index with enough info to isolate 4 points.
         */
        private double Noise3_BCC(double xr, double yr, double zr)
        {
            // Get base and offsets inside cube of first lattice.
            int    xrb = NoiseUtil.FastFloor(xr), yrb = NoiseUtil.FastFloor(yr), zrb = NoiseUtil.FastFloor(zr);
            double xri = xr - xrb, yri = yr - yrb, zri = zr - zrb;

            // Identify which octant of the cube we're in. This determines which cell
            // in the other cubic lattice we're in, and also narrows down one point on each.
            int xht = (int)(xri + 0.5), yht = (int)(yri + 0.5), zht = (int)(zri + 0.5);
            int index = (xht << 0) | (yht << 1) | (zht << 2);

            // Point contributions
            double         value = 0;
            LatticePoint3D c     = LOOKUP_3D[index];

            while (c != null)
            {
                double dxr = xri + c.dxr, dyr = yri + c.dyr, dzr = zri + c.dzr;
                double attn = 0.5 - dxr * dxr - dyr * dyr - dzr * dzr;

                if (attn < 0)
                {
                    c = c.NextOnFailure;
                }
                else
                {
                    int    pxm = (xrb + c.xrv) & PMASK, pym = (yrb + c.yrv) & PMASK, pzm = (zrb + c.zrv) & PMASK;
                    Grad3  grad          = permGrad3[perm[perm[pxm] ^ pym] ^ pzm];
                    double extrapolation = grad.dx * dxr + grad.dy * dyr + grad.dz * dzr;

                    attn  *= attn;
                    value += attn * attn * extrapolation;
                    c      = c.NextOnSuccess;
                }
            }

            return(value);
        }
Ejemplo n.º 2
0
        static OpenSimplex2F()
        {
            LOOKUP_2D   = new LatticePoint2D[4];
            LOOKUP_3D   = new LatticePoint3D[8];
            VERTICES_4D = new LatticePoint4D[16];

            LOOKUP_2D[0] = new LatticePoint2D(1, 0);
            LOOKUP_2D[1] = new LatticePoint2D(0, 0);
            LOOKUP_2D[2] = new LatticePoint2D(1, 1);
            LOOKUP_2D[3] = new LatticePoint2D(0, 1);

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, k1, i2, j2, k2;
                i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1;
                i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1;

                // The two points within this octant, one from each of the two cubic half-lattices.
                LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
                LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);

                // Each single step away on the first half-lattice.
                LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0);
                LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0);
                LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0);

                // Each single step away on the second half-lattice.
                LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1);
                LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1);
                LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1);

                // First two are guaranteed.
                c0.NextOnFailure = c0.NextOnSuccess = c1;
                c1.NextOnFailure = c1.NextOnSuccess = c2;

                // Once we find one on the first half-lattice, the rest are out.
                // In addition, knowing c2 rules out c5.
                c2.NextOnFailure = c3; c2.NextOnSuccess = c6;
                c3.NextOnFailure = c4; c3.NextOnSuccess = c5;
                c4.NextOnFailure = c4.NextOnSuccess = c5;

                // Once we find one on the second half-lattice, the rest are out.
                c5.NextOnFailure = c6; c5.NextOnSuccess = null;
                c6.NextOnFailure = c7; c6.NextOnSuccess = null;
                c7.NextOnFailure = c7.NextOnSuccess = null;

                LOOKUP_3D[i] = c0;
            }

            for (int i = 0; i < 16; i++)
            {
                VERTICES_4D[i] = new LatticePoint4D((i >> 0) & 1, (i >> 1) & 1, (i >> 2) & 1, (i >> 3) & 1);
            }

            GRADIENTS_2D = new Grad2[PSIZE];
            Grad2[] grad2 =
            {
                new Grad2(0.130526192220052,    0.99144486137381),
                new Grad2(0.38268343236509,    0.923879532511287),
                new Grad2(0.608761429008721,   0.793353340291235),
                new Grad2(0.793353340291235,   0.608761429008721),
                new Grad2(0.923879532511287,    0.38268343236509),
                new Grad2(0.99144486137381,    0.130526192220051),
                new Grad2(0.99144486137381,   -0.130526192220051),
                new Grad2(0.923879532511287,   -0.38268343236509),
                new Grad2(0.793353340291235,   -0.60876142900872),
                new Grad2(0.608761429008721,  -0.793353340291235),
                new Grad2(0.38268343236509,   -0.923879532511287),
                new Grad2(0.130526192220052,   -0.99144486137381),
                new Grad2(-0.130526192220052,  -0.99144486137381),
                new Grad2(-0.38268343236509,  -0.923879532511287),
                new Grad2(-0.608761429008721, -0.793353340291235),
                new Grad2(-0.793353340291235, -0.608761429008721),
                new Grad2(-0.923879532511287,  -0.38268343236509),
                new Grad2(-0.99144486137381,  -0.130526192220052),
                new Grad2(-0.99144486137381,   0.130526192220051),
                new Grad2(-0.923879532511287,   0.38268343236509),
                new Grad2(-0.793353340291235,  0.608761429008721),
                new Grad2(-0.608761429008721,  0.793353340291235),
                new Grad2(-0.38268343236509,   0.923879532511287),
                new Grad2(-0.130526192220052, 0.99144486137381)
            };
            for (int i = 0; i < grad2.Length; i++)
            {
                grad2[i].dx /= N2; grad2[i].dy /= N2;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_2D[i] = grad2[i % grad2.Length];
            }

            GRADIENTS_3D = new Grad3[PSIZE];
            Grad3[] grad3 =
            {
                new Grad3(-2.22474487139,           -2.22474487139,                -1.0),
                new Grad3(-2.22474487139,           -2.22474487139,                 1.0),
                new Grad3(-3.0862664687972017, -1.1721513422464978,                 0.0),
                new Grad3(-1.1721513422464978, -3.0862664687972017,                 0.0),
                new Grad3(-2.22474487139,                     -1.0,      -2.22474487139),
                new Grad3(-2.22474487139,                      1.0,      -2.22474487139),
                new Grad3(-1.1721513422464978,                 0.0, -3.0862664687972017),
                new Grad3(-3.0862664687972017,                 0.0, -1.1721513422464978),
                new Grad3(-2.22474487139,                     -1.0,       2.22474487139),
                new Grad3(-2.22474487139,                      1.0,       2.22474487139),
                new Grad3(-3.0862664687972017,                 0.0,  1.1721513422464978),
                new Grad3(-1.1721513422464978,                 0.0,  3.0862664687972017),
                new Grad3(-2.22474487139,            2.22474487139,                -1.0),
                new Grad3(-2.22474487139,            2.22474487139,                 1.0),
                new Grad3(-1.1721513422464978,  3.0862664687972017,                 0.0),
                new Grad3(-3.0862664687972017,  1.1721513422464978,                 0.0),
                new Grad3(-1.0,                     -2.22474487139,      -2.22474487139),
                new Grad3(1.0,                      -2.22474487139,      -2.22474487139),
                new Grad3(0.0,                 -3.0862664687972017, -1.1721513422464978),
                new Grad3(0.0,                 -1.1721513422464978, -3.0862664687972017),
                new Grad3(-1.0,                     -2.22474487139,       2.22474487139),
                new Grad3(1.0,                      -2.22474487139,       2.22474487139),
                new Grad3(0.0,                 -1.1721513422464978,  3.0862664687972017),
                new Grad3(0.0,                 -3.0862664687972017,  1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,      -2.22474487139),
                new Grad3(1.0,                       2.22474487139,      -2.22474487139),
                new Grad3(0.0,                  1.1721513422464978, -3.0862664687972017),
                new Grad3(0.0,                  3.0862664687972017, -1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,       2.22474487139),
                new Grad3(1.0,                       2.22474487139,       2.22474487139),
                new Grad3(0.0,                  3.0862664687972017,  1.1721513422464978),
                new Grad3(0.0,                  1.1721513422464978,  3.0862664687972017),
                new Grad3(2.22474487139,            -2.22474487139,                -1.0),
                new Grad3(2.22474487139,            -2.22474487139,                 1.0),
                new Grad3(1.1721513422464978,  -3.0862664687972017,                 0.0),
                new Grad3(3.0862664687972017,  -1.1721513422464978,                 0.0),
                new Grad3(2.22474487139,                      -1.0,      -2.22474487139),
                new Grad3(2.22474487139,                       1.0,      -2.22474487139),
                new Grad3(3.0862664687972017,                  0.0, -1.1721513422464978),
                new Grad3(1.1721513422464978,                  0.0, -3.0862664687972017),
                new Grad3(2.22474487139,                      -1.0,       2.22474487139),
                new Grad3(2.22474487139,                       1.0,       2.22474487139),
                new Grad3(1.1721513422464978,                  0.0,  3.0862664687972017),
                new Grad3(3.0862664687972017,                  0.0,  1.1721513422464978),
                new Grad3(2.22474487139,             2.22474487139,                -1.0),
                new Grad3(2.22474487139,             2.22474487139,                 1.0),
                new Grad3(3.0862664687972017,   1.1721513422464978,                 0.0),
                new Grad3(1.1721513422464978,   3.0862664687972017, 0.0)
            };
            for (int i = 0; i < grad3.Length; i++)
            {
                grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_3D[i] = grad3[i % grad3.Length];
            }

            GRADIENTS_4D = new Grad4[PSIZE];
            Grad4[] grad4 =
            {
                new Grad4(-0.753341017856078,     -0.37968289875261624,  -0.37968289875261624,  -0.37968289875261624),
                new Grad4(-0.7821684431180708,     -0.4321472685365301,   -0.4321472685365301,   0.12128480194602098),
                new Grad4(-0.7821684431180708,     -0.4321472685365301,   0.12128480194602098,   -0.4321472685365301),
                new Grad4(-0.7821684431180708,     0.12128480194602098,   -0.4321472685365301,   -0.4321472685365301),
                new Grad4(-0.8586508742123365,      -0.508629699630796,  0.044802370851755174,  0.044802370851755174),
                new Grad4(-0.8586508742123365,    0.044802370851755174,    -0.508629699630796,  0.044802370851755174),
                new Grad4(-0.8586508742123365,    0.044802370851755174,  0.044802370851755174,    -0.508629699630796),
                new Grad4(-0.9982828964265062,    -0.03381941603233842,  -0.03381941603233842,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,     -0.753341017856078,  -0.37968289875261624,  -0.37968289875261624),
                new Grad4(-0.4321472685365301,     -0.7821684431180708,   -0.4321472685365301,   0.12128480194602098),
                new Grad4(-0.4321472685365301,     -0.7821684431180708,   0.12128480194602098,   -0.4321472685365301),
                new Grad4(0.12128480194602098,     -0.7821684431180708,   -0.4321472685365301,   -0.4321472685365301),
                new Grad4(-0.508629699630796,      -0.8586508742123365,  0.044802370851755174,  0.044802370851755174),
                new Grad4(0.044802370851755174,    -0.8586508742123365,    -0.508629699630796,  0.044802370851755174),
                new Grad4(0.044802370851755174,    -0.8586508742123365,  0.044802370851755174,    -0.508629699630796),
                new Grad4(-0.03381941603233842,    -0.9982828964265062,  -0.03381941603233842,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,   -0.37968289875261624,    -0.753341017856078,  -0.37968289875261624),
                new Grad4(-0.4321472685365301,     -0.4321472685365301,   -0.7821684431180708,   0.12128480194602098),
                new Grad4(-0.4321472685365301,     0.12128480194602098,   -0.7821684431180708,   -0.4321472685365301),
                new Grad4(0.12128480194602098,     -0.4321472685365301,   -0.7821684431180708,   -0.4321472685365301),
                new Grad4(-0.508629699630796,     0.044802370851755174,   -0.8586508742123365,  0.044802370851755174),
                new Grad4(0.044802370851755174,     -0.508629699630796,   -0.8586508742123365,  0.044802370851755174),
                new Grad4(0.044802370851755174,   0.044802370851755174,   -0.8586508742123365,    -0.508629699630796),
                new Grad4(-0.03381941603233842,   -0.03381941603233842,   -0.9982828964265062,  -0.03381941603233842),
                new Grad4(-0.37968289875261624,   -0.37968289875261624,  -0.37968289875261624,    -0.753341017856078),
                new Grad4(-0.4321472685365301,     -0.4321472685365301,   0.12128480194602098,   -0.7821684431180708),
                new Grad4(-0.4321472685365301,     0.12128480194602098,   -0.4321472685365301,   -0.7821684431180708),
                new Grad4(0.12128480194602098,     -0.4321472685365301,   -0.4321472685365301,   -0.7821684431180708),
                new Grad4(-0.508629699630796,     0.044802370851755174,  0.044802370851755174,   -0.8586508742123365),
                new Grad4(0.044802370851755174,     -0.508629699630796,  0.044802370851755174,   -0.8586508742123365),
                new Grad4(0.044802370851755174,   0.044802370851755174,    -0.508629699630796,   -0.8586508742123365),
                new Grad4(-0.03381941603233842,   -0.03381941603233842,  -0.03381941603233842,   -0.9982828964265062),
                new Grad4(-0.6740059517812944,     -0.3239847771997537,   -0.3239847771997537,    0.5794684678643381),
                new Grad4(-0.7504883828755602,     -0.4004672082940195,   0.15296486218853164,    0.5029860367700724),
                new Grad4(-0.7504883828755602,     0.15296486218853164,   -0.4004672082940195,    0.5029860367700724),
                new Grad4(-0.8828161875373585,     0.08164729285680945,   0.08164729285680945,    0.4553054119602712),
                new Grad4(-0.4553054119602712,    -0.08164729285680945,  -0.08164729285680945,    0.8828161875373585),
                new Grad4(-0.5029860367700724,    -0.15296486218853164,    0.4004672082940195,    0.7504883828755602),
                new Grad4(-0.5029860367700724,      0.4004672082940195,  -0.15296486218853164,    0.7504883828755602),
                new Grad4(-0.5794684678643381,      0.3239847771997537,    0.3239847771997537,    0.6740059517812944),
                new Grad4(-0.3239847771997537,     -0.6740059517812944,   -0.3239847771997537,    0.5794684678643381),
                new Grad4(-0.4004672082940195,     -0.7504883828755602,   0.15296486218853164,    0.5029860367700724),
                new Grad4(0.15296486218853164,     -0.7504883828755602,   -0.4004672082940195,    0.5029860367700724),
                new Grad4(0.08164729285680945,     -0.8828161875373585,   0.08164729285680945,    0.4553054119602712),
                new Grad4(-0.08164729285680945,    -0.4553054119602712,  -0.08164729285680945,    0.8828161875373585),
                new Grad4(-0.15296486218853164,    -0.5029860367700724,    0.4004672082940195,    0.7504883828755602),
                new Grad4(0.4004672082940195,      -0.5029860367700724,  -0.15296486218853164,    0.7504883828755602),
                new Grad4(0.3239847771997537,      -0.5794684678643381,    0.3239847771997537,    0.6740059517812944),
                new Grad4(-0.3239847771997537,     -0.3239847771997537,   -0.6740059517812944,    0.5794684678643381),
                new Grad4(-0.4004672082940195,     0.15296486218853164,   -0.7504883828755602,    0.5029860367700724),
                new Grad4(0.15296486218853164,     -0.4004672082940195,   -0.7504883828755602,    0.5029860367700724),
                new Grad4(0.08164729285680945,     0.08164729285680945,   -0.8828161875373585,    0.4553054119602712),
                new Grad4(-0.08164729285680945,   -0.08164729285680945,   -0.4553054119602712,    0.8828161875373585),
                new Grad4(-0.15296486218853164,     0.4004672082940195,   -0.5029860367700724,    0.7504883828755602),
                new Grad4(0.4004672082940195,     -0.15296486218853164,   -0.5029860367700724,    0.7504883828755602),
                new Grad4(0.3239847771997537,       0.3239847771997537,   -0.5794684678643381,    0.6740059517812944),
                new Grad4(-0.6740059517812944,     -0.3239847771997537,    0.5794684678643381,   -0.3239847771997537),
                new Grad4(-0.7504883828755602,     -0.4004672082940195,    0.5029860367700724,   0.15296486218853164),
                new Grad4(-0.7504883828755602,     0.15296486218853164,    0.5029860367700724,   -0.4004672082940195),
                new Grad4(-0.8828161875373585,     0.08164729285680945,    0.4553054119602712,   0.08164729285680945),
                new Grad4(-0.4553054119602712,    -0.08164729285680945,    0.8828161875373585,  -0.08164729285680945),
                new Grad4(-0.5029860367700724,    -0.15296486218853164,    0.7504883828755602,    0.4004672082940195),
                new Grad4(-0.5029860367700724,      0.4004672082940195,    0.7504883828755602,  -0.15296486218853164),
                new Grad4(-0.5794684678643381,      0.3239847771997537,    0.6740059517812944,    0.3239847771997537),
                new Grad4(-0.3239847771997537,     -0.6740059517812944,    0.5794684678643381,   -0.3239847771997537),
                new Grad4(-0.4004672082940195,     -0.7504883828755602,    0.5029860367700724,   0.15296486218853164),
                new Grad4(0.15296486218853164,     -0.7504883828755602,    0.5029860367700724,   -0.4004672082940195),
                new Grad4(0.08164729285680945,     -0.8828161875373585,    0.4553054119602712,   0.08164729285680945),
                new Grad4(-0.08164729285680945,    -0.4553054119602712,    0.8828161875373585,  -0.08164729285680945),
                new Grad4(-0.15296486218853164,    -0.5029860367700724,    0.7504883828755602,    0.4004672082940195),
                new Grad4(0.4004672082940195,      -0.5029860367700724,    0.7504883828755602,  -0.15296486218853164),
                new Grad4(0.3239847771997537,      -0.5794684678643381,    0.6740059517812944,    0.3239847771997537),
                new Grad4(-0.3239847771997537,     -0.3239847771997537,    0.5794684678643381,   -0.6740059517812944),
                new Grad4(-0.4004672082940195,     0.15296486218853164,    0.5029860367700724,   -0.7504883828755602),
                new Grad4(0.15296486218853164,     -0.4004672082940195,    0.5029860367700724,   -0.7504883828755602),
                new Grad4(0.08164729285680945,     0.08164729285680945,    0.4553054119602712,   -0.8828161875373585),
                new Grad4(-0.08164729285680945,   -0.08164729285680945,    0.8828161875373585,   -0.4553054119602712),
                new Grad4(-0.15296486218853164,     0.4004672082940195,    0.7504883828755602,   -0.5029860367700724),
                new Grad4(0.4004672082940195,     -0.15296486218853164,    0.7504883828755602,   -0.5029860367700724),
                new Grad4(0.3239847771997537,       0.3239847771997537,    0.6740059517812944,   -0.5794684678643381),
                new Grad4(-0.6740059517812944,      0.5794684678643381,   -0.3239847771997537,   -0.3239847771997537),
                new Grad4(-0.7504883828755602,      0.5029860367700724,   -0.4004672082940195,   0.15296486218853164),
                new Grad4(-0.7504883828755602,      0.5029860367700724,   0.15296486218853164,   -0.4004672082940195),
                new Grad4(-0.8828161875373585,      0.4553054119602712,   0.08164729285680945,   0.08164729285680945),
                new Grad4(-0.4553054119602712,      0.8828161875373585,  -0.08164729285680945,  -0.08164729285680945),
                new Grad4(-0.5029860367700724,      0.7504883828755602,  -0.15296486218853164,    0.4004672082940195),
                new Grad4(-0.5029860367700724,      0.7504883828755602,    0.4004672082940195,  -0.15296486218853164),
                new Grad4(-0.5794684678643381,      0.6740059517812944,    0.3239847771997537,    0.3239847771997537),
                new Grad4(-0.3239847771997537,      0.5794684678643381,   -0.6740059517812944,   -0.3239847771997537),
                new Grad4(-0.4004672082940195,      0.5029860367700724,   -0.7504883828755602,   0.15296486218853164),
                new Grad4(0.15296486218853164,      0.5029860367700724,   -0.7504883828755602,   -0.4004672082940195),
                new Grad4(0.08164729285680945,      0.4553054119602712,   -0.8828161875373585,   0.08164729285680945),
                new Grad4(-0.08164729285680945,     0.8828161875373585,   -0.4553054119602712,  -0.08164729285680945),
                new Grad4(-0.15296486218853164,     0.7504883828755602,   -0.5029860367700724,    0.4004672082940195),
                new Grad4(0.4004672082940195,       0.7504883828755602,   -0.5029860367700724,  -0.15296486218853164),
                new Grad4(0.3239847771997537,       0.6740059517812944,   -0.5794684678643381,    0.3239847771997537),
                new Grad4(-0.3239847771997537,      0.5794684678643381,   -0.3239847771997537,   -0.6740059517812944),
                new Grad4(-0.4004672082940195,      0.5029860367700724,   0.15296486218853164,   -0.7504883828755602),
                new Grad4(0.15296486218853164,      0.5029860367700724,   -0.4004672082940195,   -0.7504883828755602),
                new Grad4(0.08164729285680945,      0.4553054119602712,   0.08164729285680945,   -0.8828161875373585),
                new Grad4(-0.08164729285680945,     0.8828161875373585,  -0.08164729285680945,   -0.4553054119602712),
                new Grad4(-0.15296486218853164,     0.7504883828755602,    0.4004672082940195,   -0.5029860367700724),
                new Grad4(0.4004672082940195,       0.7504883828755602,  -0.15296486218853164,   -0.5029860367700724),
                new Grad4(0.3239847771997537,       0.6740059517812944,    0.3239847771997537,   -0.5794684678643381),
                new Grad4(0.5794684678643381,      -0.6740059517812944,   -0.3239847771997537,   -0.3239847771997537),
                new Grad4(0.5029860367700724,      -0.7504883828755602,   -0.4004672082940195,   0.15296486218853164),
                new Grad4(0.5029860367700724,      -0.7504883828755602,   0.15296486218853164,   -0.4004672082940195),
                new Grad4(0.4553054119602712,      -0.8828161875373585,   0.08164729285680945,   0.08164729285680945),
                new Grad4(0.8828161875373585,      -0.4553054119602712,  -0.08164729285680945,  -0.08164729285680945),
                new Grad4(0.7504883828755602,      -0.5029860367700724,  -0.15296486218853164,    0.4004672082940195),
                new Grad4(0.7504883828755602,      -0.5029860367700724,    0.4004672082940195,  -0.15296486218853164),
                new Grad4(0.6740059517812944,      -0.5794684678643381,    0.3239847771997537,    0.3239847771997537),
                new Grad4(0.5794684678643381,      -0.3239847771997537,   -0.6740059517812944,   -0.3239847771997537),
                new Grad4(0.5029860367700724,      -0.4004672082940195,   -0.7504883828755602,   0.15296486218853164),
                new Grad4(0.5029860367700724,      0.15296486218853164,   -0.7504883828755602,   -0.4004672082940195),
                new Grad4(0.4553054119602712,      0.08164729285680945,   -0.8828161875373585,   0.08164729285680945),
                new Grad4(0.8828161875373585,     -0.08164729285680945,   -0.4553054119602712,  -0.08164729285680945),
                new Grad4(0.7504883828755602,     -0.15296486218853164,   -0.5029860367700724,    0.4004672082940195),
                new Grad4(0.7504883828755602,       0.4004672082940195,   -0.5029860367700724,  -0.15296486218853164),
                new Grad4(0.6740059517812944,       0.3239847771997537,   -0.5794684678643381,    0.3239847771997537),
                new Grad4(0.5794684678643381,      -0.3239847771997537,   -0.3239847771997537,   -0.6740059517812944),
                new Grad4(0.5029860367700724,      -0.4004672082940195,   0.15296486218853164,   -0.7504883828755602),
                new Grad4(0.5029860367700724,      0.15296486218853164,   -0.4004672082940195,   -0.7504883828755602),
                new Grad4(0.4553054119602712,      0.08164729285680945,   0.08164729285680945,   -0.8828161875373585),
                new Grad4(0.8828161875373585,     -0.08164729285680945,  -0.08164729285680945,   -0.4553054119602712),
                new Grad4(0.7504883828755602,     -0.15296486218853164,    0.4004672082940195,   -0.5029860367700724),
                new Grad4(0.7504883828755602,       0.4004672082940195,  -0.15296486218853164,   -0.5029860367700724),
                new Grad4(0.6740059517812944,       0.3239847771997537,    0.3239847771997537,   -0.5794684678643381),
                new Grad4(0.03381941603233842,     0.03381941603233842,   0.03381941603233842,    0.9982828964265062),
                new Grad4(-0.044802370851755174, -0.044802370851755174,     0.508629699630796,    0.8586508742123365),
                new Grad4(-0.044802370851755174,     0.508629699630796, -0.044802370851755174,    0.8586508742123365),
                new Grad4(-0.12128480194602098,     0.4321472685365301,    0.4321472685365301,    0.7821684431180708),
                new Grad4(0.508629699630796,     -0.044802370851755174, -0.044802370851755174,    0.8586508742123365),
                new Grad4(0.4321472685365301,     -0.12128480194602098,    0.4321472685365301,    0.7821684431180708),
                new Grad4(0.4321472685365301,       0.4321472685365301,  -0.12128480194602098,    0.7821684431180708),
                new Grad4(0.37968289875261624,     0.37968289875261624,   0.37968289875261624,     0.753341017856078),
                new Grad4(0.03381941603233842,     0.03381941603233842,    0.9982828964265062,   0.03381941603233842),
                new Grad4(-0.044802370851755174,  0.044802370851755174,    0.8586508742123365,     0.508629699630796),
                new Grad4(-0.044802370851755174,     0.508629699630796,    0.8586508742123365, -0.044802370851755174),
                new Grad4(-0.12128480194602098,     0.4321472685365301,    0.7821684431180708,    0.4321472685365301),
                new Grad4(0.508629699630796,     -0.044802370851755174,    0.8586508742123365, -0.044802370851755174),
                new Grad4(0.4321472685365301,     -0.12128480194602098,    0.7821684431180708,    0.4321472685365301),
                new Grad4(0.4321472685365301,       0.4321472685365301,    0.7821684431180708,  -0.12128480194602098),
                new Grad4(0.37968289875261624,     0.37968289875261624,     0.753341017856078,   0.37968289875261624),
                new Grad4(0.03381941603233842,      0.9982828964265062,   0.03381941603233842,   0.03381941603233842),
                new Grad4(-0.044802370851755174,    0.8586508742123365, -0.044802370851755174,     0.508629699630796),
                new Grad4(-0.044802370851755174,    0.8586508742123365,     0.508629699630796, -0.044802370851755174),
                new Grad4(-0.12128480194602098,     0.7821684431180708,    0.4321472685365301,    0.4321472685365301),
                new Grad4(0.508629699630796,        0.8586508742123365, -0.044802370851755174, -0.044802370851755174),
                new Grad4(0.4321472685365301,       0.7821684431180708,  -0.12128480194602098,    0.4321472685365301),
                new Grad4(0.4321472685365301,       0.7821684431180708,    0.4321472685365301,  -0.12128480194602098),
                new Grad4(0.37968289875261624,       0.753341017856078,   0.37968289875261624,   0.37968289875261624),
                new Grad4(0.9982828964265062,      0.03381941603233842,   0.03381941603233842,   0.03381941603233842),
                new Grad4(0.8586508742123365,    -0.044802370851755174, -0.044802370851755174,     0.508629699630796),
                new Grad4(0.8586508742123365,    -0.044802370851755174,     0.508629699630796, -0.044802370851755174),
                new Grad4(0.7821684431180708,     -0.12128480194602098,    0.4321472685365301,    0.4321472685365301),
                new Grad4(0.8586508742123365,        0.508629699630796, -0.044802370851755174, -0.044802370851755174),
                new Grad4(0.7821684431180708,       0.4321472685365301,  -0.12128480194602098,    0.4321472685365301),
                new Grad4(0.7821684431180708,       0.4321472685365301,    0.4321472685365301,  -0.12128480194602098),
                new Grad4(0.753341017856078,       0.37968289875261624,   0.37968289875261624, 0.37968289875261624)
            };
            for (int i = 0; i < grad4.Length; i++)
            {
                grad4[i].dx /= N4; grad4[i].dy /= N4; grad4[i].dz /= N4; grad4[i].dw /= N4;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_4D[i] = grad4[i % grad4.Length];
            }
        }
Ejemplo n.º 3
0
        static FastSimplexStyleNoise()
        {
            LOOKUP_2D = new LatticePoint2D[2 * 3];
            LOOKUP_3D = new LatticePoint3D[8];

            for (int i = 0; i < 2; i++)
            {
                int i1, j1;
                if ((i & 1) == 0)
                {
                    i1 = 1; j1 = 0;
                }
                else
                {
                    i1 = 0; j1 = 1;
                }
                LOOKUP_2D[i * 3 + 0] = new LatticePoint2D(0, 0);
                LOOKUP_2D[i * 3 + 1] = new LatticePoint2D(1, 1);
                LOOKUP_2D[i * 3 + 2] = new LatticePoint2D(i1, j1);
            }

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, k1, i2, j2, k2;
                i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1;
                i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1;

                // The two points within this octant, one from each of the two cubic half-lattices.
                LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
                LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);

                // Each single step away on the first half-lattice.
                LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0);
                LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1, 0);
                LatticePoint3D c4 = new LatticePoint3D(i1, j1, k1 ^ 1, 0);

                // Each single step away on the second half-lattice.
                LatticePoint3D c5 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1);
                LatticePoint3D c6 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1);
                LatticePoint3D c7 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1);

                // First two are guaranteed.
                c0.NextOnFailure = c0.NextOnSuccess = c1;
                c1.NextOnFailure = c1.NextOnSuccess = c2;

                // Once we find one on the first half-lattice, the rest are out.
                // In addition, knowing c2 rules out c5.
                c2.NextOnFailure = c3; c2.NextOnSuccess = c6;
                c3.NextOnFailure = c4; c3.NextOnSuccess = c5;
                c4.NextOnFailure = c4.NextOnSuccess = c5;

                // Once we find one on the second half-lattice, the rest are out.
                c5.NextOnFailure = c6; c5.NextOnSuccess = null;
                c6.NextOnFailure = c7; c6.NextOnSuccess = null;
                c7.NextOnFailure = c7.NextOnSuccess = null;

                LOOKUP_3D[i] = c0;
            }

            GRADIENTS_2D = new Grad2[PSIZE];
            Grad2[] grad2 =
            {
                new Grad2(0.0,                                 1.0),
                new Grad2(0.5,                  0.8660254037844387),
                new Grad2(0.8660254037844387,                  0.5),
                new Grad2(1.0,                                 0.0),
                new Grad2(0.8660254037844387,                 -0.5),
                new Grad2(0.5,                 -0.8660254037844387),
                new Grad2(0.0,                                -1.0),
                new Grad2(-0.5,                -0.8660254037844387),
                new Grad2(-0.8660254037844387,                -0.5),
                new Grad2(-1.0,                                0.0),
                new Grad2(-0.8660254037844387,                 0.5),
                new Grad2(-0.5, 0.8660254037844387)
            };
            for (int i = 0; i < grad2.Length; i++)
            {
                grad2[i].dx /= N2; grad2[i].dy /= N2;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_2D[i] = grad2[i % grad2.Length];
            }

            GRADIENTS_3D = new Grad3[PSIZE];
            Grad3[] grad3 =
            {
                new Grad3(-2.22474487139,           -2.22474487139,                -1.0),
                new Grad3(-2.22474487139,           -2.22474487139,                 1.0),
                new Grad3(-3.0862664687972017, -1.1721513422464978,                 0.0),
                new Grad3(-1.1721513422464978, -3.0862664687972017,                 0.0),
                new Grad3(-2.22474487139,                     -1.0,      -2.22474487139),
                new Grad3(-2.22474487139,                      1.0,      -2.22474487139),
                new Grad3(-1.1721513422464978,                 0.0, -3.0862664687972017),
                new Grad3(-3.0862664687972017,                 0.0, -1.1721513422464978),
                new Grad3(-2.22474487139,                     -1.0,       2.22474487139),
                new Grad3(-2.22474487139,                      1.0,       2.22474487139),
                new Grad3(-3.0862664687972017,                 0.0,  1.1721513422464978),
                new Grad3(-1.1721513422464978,                 0.0,  3.0862664687972017),
                new Grad3(-2.22474487139,            2.22474487139,                -1.0),
                new Grad3(-2.22474487139,            2.22474487139,                 1.0),
                new Grad3(-1.1721513422464978,  3.0862664687972017,                 0.0),
                new Grad3(-3.0862664687972017,  1.1721513422464978,                 0.0),
                new Grad3(-1.0,                     -2.22474487139,      -2.22474487139),
                new Grad3(1.0,                      -2.22474487139,      -2.22474487139),
                new Grad3(0.0,                 -3.0862664687972017, -1.1721513422464978),
                new Grad3(0.0,                 -1.1721513422464978, -3.0862664687972017),
                new Grad3(-1.0,                     -2.22474487139,       2.22474487139),
                new Grad3(1.0,                      -2.22474487139,       2.22474487139),
                new Grad3(0.0,                 -1.1721513422464978,  3.0862664687972017),
                new Grad3(0.0,                 -3.0862664687972017,  1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,      -2.22474487139),
                new Grad3(1.0,                       2.22474487139,      -2.22474487139),
                new Grad3(0.0,                  1.1721513422464978, -3.0862664687972017),
                new Grad3(0.0,                  3.0862664687972017, -1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,       2.22474487139),
                new Grad3(1.0,                       2.22474487139,       2.22474487139),
                new Grad3(0.0,                  3.0862664687972017,  1.1721513422464978),
                new Grad3(0.0,                  1.1721513422464978,  3.0862664687972017),
                new Grad3(2.22474487139,            -2.22474487139,                -1.0),
                new Grad3(2.22474487139,            -2.22474487139,                 1.0),
                new Grad3(1.1721513422464978,  -3.0862664687972017,                 0.0),
                new Grad3(3.0862664687972017,  -1.1721513422464978,                 0.0),
                new Grad3(2.22474487139,                      -1.0,      -2.22474487139),
                new Grad3(2.22474487139,                       1.0,      -2.22474487139),
                new Grad3(3.0862664687972017,                  0.0, -1.1721513422464978),
                new Grad3(1.1721513422464978,                  0.0, -3.0862664687972017),
                new Grad3(2.22474487139,                      -1.0,       2.22474487139),
                new Grad3(2.22474487139,                       1.0,       2.22474487139),
                new Grad3(1.1721513422464978,                  0.0,  3.0862664687972017),
                new Grad3(3.0862664687972017,                  0.0,  1.1721513422464978),
                new Grad3(2.22474487139,             2.22474487139,                -1.0),
                new Grad3(2.22474487139,             2.22474487139,                 1.0),
                new Grad3(3.0862664687972017,   1.1721513422464978,                 0.0),
                new Grad3(1.1721513422464978,   3.0862664687972017, 0.0)
            };
            for (int i = 0; i < grad3.Length; i++)
            {
                grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_3D[i] = grad3[i % grad3.Length];
            }
        }
Ejemplo n.º 4
0
        static OpenSimplex2S()
        {
            LOOKUP_2D = new LatticePoint2D[8 * 4];
            LOOKUP_3D = new LatticePoint3D[8];

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, i2, j2;
                if ((i & 1) == 0)
                {
                    if ((i & 2) == 0)
                    {
                        i1 = -1; j1 = 0;
                    }
                    else
                    {
                        i1 = 1; j1 = 0;
                    }
                    if ((i & 4) == 0)
                    {
                        i2 = 0; j2 = -1;
                    }
                    else
                    {
                        i2 = 0; j2 = 1;
                    }
                }
                else
                {
                    if ((i & 2) != 0)
                    {
                        i1 = 2; j1 = 1;
                    }
                    else
                    {
                        i1 = 0; j1 = 1;
                    }
                    if ((i & 4) != 0)
                    {
                        i2 = 1; j2 = 2;
                    }
                    else
                    {
                        i2 = 1; j2 = 0;
                    }
                }
                LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(0, 0);
                LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(1, 1);
                LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1);
                LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2);
            }

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, k1, i2, j2, k2;
                i1 = (i >> 0) & 1; j1 = (i >> 1) & 1; k1 = (i >> 2) & 1;
                i2 = i1 ^ 1; j2 = j1 ^ 1; k2 = k1 ^ 1;

                // The two points within this octant, one from each of the two cubic half-lattices.
                LatticePoint3D c0 = new LatticePoint3D(i1, j1, k1, 0);
                LatticePoint3D c1 = new LatticePoint3D(i1 + i2, j1 + j2, k1 + k2, 1);

                // (1, 0, 0) vs (0, 1, 1) away from octant.
                LatticePoint3D c2 = new LatticePoint3D(i1 ^ 1, j1, k1, 0);
                LatticePoint3D c3 = new LatticePoint3D(i1, j1 ^ 1, k1 ^ 1, 0);

                // (1, 0, 0) vs (0, 1, 1) away from octant, on second half-lattice.
                LatticePoint3D c4 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + k2, 1);
                LatticePoint3D c5 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + (k2 ^ 1), 1);

                // (0, 1, 0) vs (1, 0, 1) away from octant.
                LatticePoint3D c6 = new LatticePoint3D(i1, j1 ^ 1, k1, 0);
                LatticePoint3D c7 = new LatticePoint3D(i1 ^ 1, j1, k1 ^ 1, 0);

                // (0, 1, 0) vs (1, 0, 1) away from octant, on second half-lattice.
                LatticePoint3D c8 = new LatticePoint3D(i1 + i2, j1 + (j2 ^ 1), k1 + k2, 1);
                LatticePoint3D c9 = new LatticePoint3D(i1 + (i2 ^ 1), j1 + j2, k1 + (k2 ^ 1), 1);

                // (0, 0, 1) vs (1, 1, 0) away from octant.
                LatticePoint3D cA = new LatticePoint3D(i1, j1, k1 ^ 1, 0);
                LatticePoint3D cB = new LatticePoint3D(i1 ^ 1, j1 ^ 1, k1, 0);

                // (0, 0, 1) vs (1, 1, 0) away from octant, on second half-lattice.
                LatticePoint3D cC = new LatticePoint3D(i1 + i2, j1 + j2, k1 + (k2 ^ 1), 1);
                LatticePoint3D cD = new LatticePoint3D(i1 + (i2 ^ 1), j1 + (j2 ^ 1), k1 + k2, 1);

                // First two points are guaranteed.
                c0.NextOnFailure = c0.NextOnSuccess = c1;
                c1.NextOnFailure = c1.NextOnSuccess = c2;

                // If c2 is in range, then we know c3 and c4 are not.
                c2.NextOnFailure = c3; c2.NextOnSuccess = c5;
                c3.NextOnFailure = c4; c3.NextOnSuccess = c4;

                // If c4 is in range, then we know c5 is not.
                c4.NextOnFailure = c5; c4.NextOnSuccess = c6;
                c5.NextOnFailure = c5.NextOnSuccess = c6;

                // If c6 is in range, then we know c7 and c8 are not.
                c6.NextOnFailure = c7; c6.NextOnSuccess = c9;
                c7.NextOnFailure = c8; c7.NextOnSuccess = c8;

                // If c8 is in range, then we know c9 is not.
                c8.NextOnFailure = c9; c8.NextOnSuccess = cA;
                c9.NextOnFailure = c9.NextOnSuccess = cA;

                // If cA is in range, then we know cB and cC are not.
                cA.NextOnFailure = cB; cA.NextOnSuccess = cD;
                cB.NextOnFailure = cC; cB.NextOnSuccess = cC;

                // If cC is in range, then we know cD is not.
                cC.NextOnFailure = cD; cC.NextOnSuccess = null;
                cD.NextOnFailure = cD.NextOnSuccess = null;

                LOOKUP_3D[i] = c0;
            }

            GRADIENTS_2D = new Grad2[PSIZE];
            Grad2[] grad2 =
            {
                new Grad2(0.130526192220052,    0.99144486137381),
                new Grad2(0.38268343236509,    0.923879532511287),
                new Grad2(0.608761429008721,   0.793353340291235),
                new Grad2(0.793353340291235,   0.608761429008721),
                new Grad2(0.923879532511287,    0.38268343236509),
                new Grad2(0.99144486137381,    0.130526192220051),
                new Grad2(0.99144486137381,   -0.130526192220051),
                new Grad2(0.923879532511287,   -0.38268343236509),
                new Grad2(0.793353340291235,   -0.60876142900872),
                new Grad2(0.608761429008721,  -0.793353340291235),
                new Grad2(0.38268343236509,   -0.923879532511287),
                new Grad2(0.130526192220052,   -0.99144486137381),
                new Grad2(-0.130526192220052,  -0.99144486137381),
                new Grad2(-0.38268343236509,  -0.923879532511287),
                new Grad2(-0.608761429008721, -0.793353340291235),
                new Grad2(-0.793353340291235, -0.608761429008721),
                new Grad2(-0.923879532511287,  -0.38268343236509),
                new Grad2(-0.99144486137381,  -0.130526192220052),
                new Grad2(-0.99144486137381,   0.130526192220051),
                new Grad2(-0.923879532511287,   0.38268343236509),
                new Grad2(-0.793353340291235,  0.608761429008721),
                new Grad2(-0.608761429008721,  0.793353340291235),
                new Grad2(-0.38268343236509,   0.923879532511287),
                new Grad2(-0.130526192220052, 0.99144486137381)
            };
            for (int i = 0; i < grad2.Length; i++)
            {
                grad2[i].dx /= N2; grad2[i].dy /= N2;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_2D[i] = grad2[i % grad2.Length];
            }

            GRADIENTS_3D = new Grad3[PSIZE];
            Grad3[] grad3 =
            {
                new Grad3(-2.22474487139,           -2.22474487139,                -1.0),
                new Grad3(-2.22474487139,           -2.22474487139,                 1.0),
                new Grad3(-3.0862664687972017, -1.1721513422464978,                 0.0),
                new Grad3(-1.1721513422464978, -3.0862664687972017,                 0.0),
                new Grad3(-2.22474487139,                     -1.0,      -2.22474487139),
                new Grad3(-2.22474487139,                      1.0,      -2.22474487139),
                new Grad3(-1.1721513422464978,                 0.0, -3.0862664687972017),
                new Grad3(-3.0862664687972017,                 0.0, -1.1721513422464978),
                new Grad3(-2.22474487139,                     -1.0,       2.22474487139),
                new Grad3(-2.22474487139,                      1.0,       2.22474487139),
                new Grad3(-3.0862664687972017,                 0.0,  1.1721513422464978),
                new Grad3(-1.1721513422464978,                 0.0,  3.0862664687972017),
                new Grad3(-2.22474487139,            2.22474487139,                -1.0),
                new Grad3(-2.22474487139,            2.22474487139,                 1.0),
                new Grad3(-1.1721513422464978,  3.0862664687972017,                 0.0),
                new Grad3(-3.0862664687972017,  1.1721513422464978,                 0.0),
                new Grad3(-1.0,                     -2.22474487139,      -2.22474487139),
                new Grad3(1.0,                      -2.22474487139,      -2.22474487139),
                new Grad3(0.0,                 -3.0862664687972017, -1.1721513422464978),
                new Grad3(0.0,                 -1.1721513422464978, -3.0862664687972017),
                new Grad3(-1.0,                     -2.22474487139,       2.22474487139),
                new Grad3(1.0,                      -2.22474487139,       2.22474487139),
                new Grad3(0.0,                 -1.1721513422464978,  3.0862664687972017),
                new Grad3(0.0,                 -3.0862664687972017,  1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,      -2.22474487139),
                new Grad3(1.0,                       2.22474487139,      -2.22474487139),
                new Grad3(0.0,                  1.1721513422464978, -3.0862664687972017),
                new Grad3(0.0,                  3.0862664687972017, -1.1721513422464978),
                new Grad3(-1.0,                      2.22474487139,       2.22474487139),
                new Grad3(1.0,                       2.22474487139,       2.22474487139),
                new Grad3(0.0,                  3.0862664687972017,  1.1721513422464978),
                new Grad3(0.0,                  1.1721513422464978,  3.0862664687972017),
                new Grad3(2.22474487139,            -2.22474487139,                -1.0),
                new Grad3(2.22474487139,            -2.22474487139,                 1.0),
                new Grad3(1.1721513422464978,  -3.0862664687972017,                 0.0),
                new Grad3(3.0862664687972017,  -1.1721513422464978,                 0.0),
                new Grad3(2.22474487139,                      -1.0,      -2.22474487139),
                new Grad3(2.22474487139,                       1.0,      -2.22474487139),
                new Grad3(3.0862664687972017,                  0.0, -1.1721513422464978),
                new Grad3(1.1721513422464978,                  0.0, -3.0862664687972017),
                new Grad3(2.22474487139,                      -1.0,       2.22474487139),
                new Grad3(2.22474487139,                       1.0,       2.22474487139),
                new Grad3(1.1721513422464978,                  0.0,  3.0862664687972017),
                new Grad3(3.0862664687972017,                  0.0,  1.1721513422464978),
                new Grad3(2.22474487139,             2.22474487139,                -1.0),
                new Grad3(2.22474487139,             2.22474487139,                 1.0),
                new Grad3(3.0862664687972017,   1.1721513422464978,                 0.0),
                new Grad3(1.1721513422464978,   3.0862664687972017, 0.0)
            };
            for (int i = 0; i < grad3.Length; i++)
            {
                grad3[i].dx /= N3; grad3[i].dy /= N3; grad3[i].dz /= N3;
            }
            for (int i = 0; i < PSIZE; i++)
            {
                GRADIENTS_3D[i] = grad3[i % grad3.Length];
            }
        }