public virtual void GetValue(double x, double y, ISimplexData2D data)
        {
            //Get points for A2 lattice
            double s  = _stretch2D * (x + y);
            double xs = x + s;
            double ys = y + s;

            //Get base points and offsets
            int    xsb = Libnoise.FastFloor(xs);
            int    ysb = Libnoise.FastFloor(ys);
            double xsi = xs - xsb;
            double ysi = ys - ysb;

            //Index to point list
            int a     = (int)(ysi - xsi + 1);
            int index = (a << 2) | (int)(xsi + ysi / 2.0 + a / 2.0) << 3 |
                        (int)(ysi + xsi / 2.0 + 1.0 / 2.0 - a / 2.0) << 4;

            //Get unskewed offsets.
            double ssi = (xsi + ysi) * _squish2D;
            double xi  = xsi + ssi;
            double yi  = ysi + ssi;

            // clear data
            data.Clear();

            //Point contributions
            for (int i = 0; i < 4; i++)
            {
                LatticePoint2D lattice = _lookup2D[index + i];

                double dx   = xi + lattice.Dx;
                double dy   = yi + lattice.Dy;
                double attn = 2.0 - (dx * dx) - (dy * dy);
                if (attn <= 0)
                {
                    continue;
                }

                int    pxm    = (xsb + lattice.Xsv) & 1023;
                int    pym    = (ysb + lattice.Ysv) & 1023;
                int    giP    = _perm[pxm] ^ pym;
                int    gi     = _perm2D[giP];
                double gx     = Gradients2D[gi];
                double gy     = Gradients2D[gi + 1];
                double extrp  = gx * dx + gy * dy;
                int    giSph2 = _perm2DSph2[giP];
                data.Request().Apply(attn, extrp, gx, gy, giSph2, dx, dy);
            }
        }
Beispiel #2
0
        /*
         * Standard functions
         */

        //2D OpenSimplex noise (KdotJPG)
        public double noise(double x, double y)
        {
            double value = 0;

            //Get points for A2 lattice
            double s = STRETCH_2D * (x + y);
            double xs = x + s, ys = y + s;

            //Get base points and offsets
            int    xsb = fastFloor(xs), ysb = fastFloor(ys);
            double xsi = xs - xsb, ysi = ys - ysb;

            //Index to point list
            int a     = (int)(ysi - xsi + 1);
            int index =
                (a << 2) |
                (int)(xsi + ysi / 2.0 + a / 2.0) << 3 |
                    (int)(ysi + xsi / 2.0 + 1.0 / 2.0 - a / 2.0) << 4;

            //Get unskewed offsets.
            double ssi = (xsi + ysi) * SQUISH_2D;
            double xi = xsi + ssi, yi = ysi + ssi;

            //Point contributions
            for (int i = 0; i < 4; i++)
            {
                LatticePoint2D c = LOOKUP_2D[index + i];

                double dx = xi + c.dx, dy = yi + c.dy;
                double attn = 2.0 - dx * dx - dy * dy;
                if (attn <= 0)
                {
                    continue;
                }

                int    pxm = (xsb + c.xsv) & 1023, pym = (ysb + c.ysv) & 1023;
                int    gi            = perm2D[perm[pxm] ^ pym];
                double extrapolation = GRADIENTS_2D[gi] * dx
                                       + GRADIENTS_2D[gi + 1] * dy;

                attn  *= attn;
                value += attn * attn * extrapolation;
            }

            return(value);
        }
Beispiel #3
0
        public void evaluateNoise(double x, double y, DataStore data)
        {
            //Get points for A2 lattice
            double s = STRETCH_2D * (x + y);
            double xs = x + s, ys = y + s;

            //Get base points and offsets
            int    xsb = fastFloor(xs), ysb = fastFloor(ys);
            double xsi = xs - xsb, ysi = ys - ysb;

            //Index to point list
            int a     = (int)(ysi - xsi + 1);
            int index =
                (a << 2) |
                (int)(xsi + ysi / 2.0 + a / 2.0) << 3 |
                    (int)(ysi + xsi / 2.0 + 1.0 / 2.0 - a / 2.0) << 4;

            //Get unskewed offsets.
            double ssi = (xsi + ysi) * SQUISH_2D;
            double xi = xsi + ssi, yi = ysi + ssi;

            // clear data
            data.clear();
            //Point contributions
            for (int i = 0; i < 4; i++)
            {
                LatticePoint2D c = LOOKUP_2D[index + i];

                double dx = xi + c.dx, dy = yi + c.dy;
                double attn = 2.0 - dx * dx - dy * dy;
                if (attn <= 0)
                {
                    continue;
                }

                int    pxm = (xsb + c.xsv) & 1023, pym = (ysb + c.ysv) & 1023;
                int    gi_p = perm[pxm] ^ pym;
                int    gi = perm2D[gi_p];
                double gx = GRADIENTS_2D[gi + 0], gy = GRADIENTS_2D[gi + 1];
                double extrapolation = gx * dx + gy * dy;
                int    gi_sph2       = perm2D_sph2[gi_p];
                data.request().record(attn, extrapolation, gx, gy, gi_sph2, dx, dy);
            }
        }
Beispiel #4
0
        private double noise2_Base(double xs, double ys)
        {
            double value = 0;

            // Get base points and offsets
            int    xsb = FastFloor(xs), ysb = FastFloor(ys);
            double xsi = xs - xsb, ysi = ys - ysb;

            // Index to point list
            int a     = (int)(xsi + ysi);
            int index =
                (a << 2) |
                (int)(xsi - ysi / 2 + 1 - a / 2.0) << 3 |
                    (int)(ysi - xsi / 2 + 1 - a / 2.0) << 4;

            double ssi = (xsi + ysi) * -0.211324865405187;
            double xi = xsi + ssi, yi = ysi + ssi;

            // Point contributions
            for (int i = 0; i < 4; i++)
            {
                LatticePoint2D c = LOOKUP_2D[index + i];

                double dx = xi + c.dx, dy = yi + c.dy;
                double attn = 2.0 / 3.0 - dx * dx - dy * dy;
                if (attn <= 0)
                {
                    continue;
                }

                int    pxm = (xsb + c.xsv) & PMASK, pym = (ysb + c.ysv) & PMASK;
                Grad2  grad          = permGrad2[perm[pxm] ^ pym];
                double extrapolation = grad.dx * dx + grad.dy * dy;

                attn  *= attn;
                value += attn * attn * extrapolation;
            }

            return(value);
        }
Beispiel #5
0
        static OpenSimplexNoise()
        {
            LOOKUP_2D = new LatticePoint2D[32];

            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);
            }

            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];
            }
        }
Beispiel #6
0
        static void temp()
        {
            LOOKUP_2D = new LatticePoint2D[18 * 9];

            for (int i = 0; i < 18; i++)
            {
                int i1, j1, i2, j2, i3, j3, i4, j4, i5, j5;
                int a = (i & 1);
                int b = (i / 2) % 3;
                int c = (i / 6) % 3;
                if (a == 0)
                {
                    i1 = -1; j1 = -1;
                }
                else
                {
                    i1 = 2; j1 = 2;
                }
                if (b < 2)
                {
                    i2 = -1; j2 = 0;
                }
                else
                {
                    i2 = 2; j2 = 0;
                }
                if (b < 1)
                {
                    i3 = -1; j3 = 1;
                }
                else
                {
                    i3 = 2; j3 = 1;
                }
                if (c < 2)
                {
                    i4 = 0; j4 = -1;
                }
                else
                {
                    i4 = 0; j4 = 2;
                }
                if (c < 1)
                {
                    i5 = 1; j5 = -1;
                }
                else
                {
                    i5 = 1; j5 = 2;
                }
                LOOKUP_2D[i * 9 + 0] = new LatticePoint2D(0, 0);
                LOOKUP_2D[i * 9 + 1] = new LatticePoint2D(1, 0);
                LOOKUP_2D[i * 9 + 2] = new LatticePoint2D(0, 1);
                LOOKUP_2D[i * 9 + 3] = new LatticePoint2D(1, 1);
                LOOKUP_2D[i * 9 + 4] = new LatticePoint2D(i1, j1);
                LOOKUP_2D[i * 9 + 5] = new LatticePoint2D(i2, j2);
                LOOKUP_2D[i * 9 + 6] = new LatticePoint2D(i3, j3);
                LOOKUP_2D[i * 9 + 7] = new LatticePoint2D(i4, j4);
                LOOKUP_2D[i * 9 + 8] = new LatticePoint2D(i5, j5);
            }
        }
Beispiel #7
0
        public double[] eval(double x, double y)
        {
            extant = 0;// clear the point record
            double[] results = new double[2];
            results[0] = double.PositiveInfinity;
            results[1] = double.PositiveInfinity;
            // set the found points to not found
            pointIndex[0] = -2;
            pointIndex[1] = -2;

            //Get points for A2* lattice
            double s = 0.366025403784439 * (x + y);
            double xs = x + s, ys = y + s;

            string complaint = null;

            //Get base points and offsets
            int    xsb = fastFloor(xs), ysb = fastFloor(ys);
            double xsi = xs - xsb, ysi = ys - ysb;

            //Index to point list
            int index =
                ((int)(xsi + ysi) * 9) +
                ((int)(xsi * 2 - ysi + 1) * 9 * 2) +
                ((int)(ysi * 2 - xsi + 1) * 9 * 6);

            //Offsets in input space
            double ssi = (xsi + ysi) * -0.211324865405187;
            double xi = xsi + ssi, yi = ysi + ssi;

            if (crashing)
            {
                complaint  = "" + x;
                complaint += " " + y;
                complaint += " " + (int)(x * 1875.0);
                complaint += " " + (int)(y * 1875.0);
            }

            //Point contributions
            for (int i = 0; i < 9; i++)
            {
                LatticePoint2D c = LOOKUP_2D[index + i];
                int            pxm = (xsb + c.xsv) & 1023, pym = (ysb + c.ysv) & 1023;
                int            ji = perm2D[perm[pxm] ^ pym];
                double         jx = JITTER_2D[ji + 0], jy = JITTER_2D[ji + 1];
                // suppress points to close to existing ones
                //if (tooClose(jx -c.dx,jy - c.dy)) continue;
                double djx      = jx - (c.dx + xi),
                       djy      = jy - (c.dy + yi);
                double distance = Math.Sqrt(djx * djx + djy * djy);

                if (crashing)
                {
                    complaint += "" + i + " " + (jx - c.dx) + " " + (jy - c.dy) + " " + distance + " ";
                }
                int closeTo = pointTooClose(jx - c.dx, jy - c.dy);
                if (closeTo != -1)
                {
                    // just replace existing points if appropriate
                    if (pointIndex[f1Index] == i)
                    {
                        if (distance < results[f1Index])
                        {
                            results[f1Index]    = distance;
                            pointIndex[f1Index] = i;
                        }
                    }
                    if (pointIndex[f2Index] == i)
                    {
                        if (distance < results[f1Index])
                        {
                            // complicated; the old point was #2 and the new is #1
                            results[f2Index]    = results[f1Index];
                            pointIndex[f2Index] = pointIndex[f1Index];
                            results[f1Index]    = distance;
                            pointIndex[f1Index] = i;
                        }
                        else if (distance < results[f2Index])
                        {
                            results[f2Index]    = distance;
                            pointIndex[f2Index] = i;
                        }
                    }
                }
                else
                {
                    if (f2Index >= 0)
                    {
                        if (distance < results[f2Index])
                        {
                            results[f2Index]    = distance;
                            pointIndex[f2Index] = i;
                            if (distance < results[f1Index])
                            {
                                results[f2Index]    = results[f1Index];
                                pointIndex[f2Index] = pointIndex[f1Index];
                                results[f1Index]    = distance;
                                pointIndex[f1Index] = i;
                            }
                        }
                    }
                    else if (f1Index >= 0)
                    {
                        if (distance < results[f1Index])
                        {
                            results[f1Index]    = distance;
                            pointIndex[f1Index] = i;
                        }
                    }
                }
            }

            if (crashing)
            {
                complaint += pointIndex[f1Index] + " " + results[f1Index] + " ";
                complaint += pointIndex[f2Index] + " " + results[f2Index] + " ";
                if (otherSide == null)
                {
                    otherSide = complaint;
                }
                else
                {
                    //throw new RuntimeException(otherSide + "        " + complaint + " " + chunkManagerProblems);
                }
                crashing = false;
            }
            if (results[0] > results[1])
            {
                throw new Exception();
            }
            return(results);
        }
Beispiel #8
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];
            }
        }
Beispiel #9
0
        static void temp()
        {
            //2D (KdotJPG)
            LOOKUP_2D = new LatticePoint2D[8 * 4];
            for (int i = 0; i < 8; i++)
            {
                int i1, j1, i2, j2;
                if ((i & 1) == 0)
                {
                    if ((i & 2) == 0)
                    {
                        i1 = 0; j1 = 0;
                    }
                    else
                    {
                        i1 = 2; j1 = 0;
                    }
                    if ((i & 4) == 0)
                    {
                        i2 = 1; j2 = -1;
                    }
                    else
                    {
                        i2 = 1; j2 = 1;
                    }
                }
                else
                {
                    if ((i & 2) == 0)
                    {
                        i1 = -1; j1 = 1;
                    }
                    else
                    {
                        i1 = 1; j1 = 1;
                    }
                    if ((i & 4) == 0)
                    {
                        i2 = 0; j2 = 0;
                    }
                    else
                    {
                        i2 = 0; j2 = 2;
                    }
                }
                LOOKUP_2D[i * 4 + 0] = new LatticePoint2D(1, 0);
                LOOKUP_2D[i * 4 + 1] = new LatticePoint2D(0, 1);
                LOOKUP_2D[i * 4 + 2] = new LatticePoint2D(i1, j1);
                LOOKUP_2D[i * 4 + 3] = new LatticePoint2D(i2, j2);
            }

            //3D (DigitalShadow)
            int[][] base3D = new int[][] {
                new int[] { 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1 },
                new int[] { 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1 },
                new int[] { 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1 }
            };
            int[] p3D           = new int[] { 0, 0, 1, -1, 0, 0, 1, 0, -1, 0, 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, -1, 0, 1, 0, 0, -1, 1, 0, 2, 1, 1, 0, 1, 1, 1, -1, 0, 2, 1, 0, 1, 1, 1, -1, 1, 0, 2, 0, 1, 1, 1, -1, 1, 1, 1, 3, 2, 1, 0, 3, 1, 2, 0, 1, 3, 2, 0, 1, 3, 1, 0, 2, 1, 3, 0, 2, 1, 3, 0, 1, 2, 1, 1, 1, 0, 0, 2, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 2, 0, 1, 1, 0, 0, 1, 2, 0, 0, 2, 2, 0, 0, 0, 0, 1, 1, -1, 1, 2, 0, 0, 0, 0, 1, -1, 1, 1, 2, 0, 0, 0, 0, 1, 1, 1, -1, 2, 3, 1, 1, 1, 2, 0, 0, 2, 2, 3, 1, 1, 1, 2, 2, 0, 0, 2, 3, 1, 1, 1, 2, 0, 2, 0, 2, 1, 1, -1, 1, 2, 0, 0, 2, 2, 1, 1, -1, 1, 2, 2, 0, 0, 2, 1, -1, 1, 1, 2, 0, 0, 2, 2, 1, -1, 1, 1, 2, 0, 2, 0, 2, 1, 1, 1, -1, 2, 2, 0, 0, 2, 1, 1, 1, -1, 2, 0, 2, 0 };
            int[] lookupPairs3D = new int[] { 0, 2, 1, 1, 2, 2, 5, 1, 6, 0, 7, 0, 32, 2, 34, 2, 129, 1, 133, 1, 160, 5, 161, 5, 518, 0, 519, 0, 546, 4, 550, 4, 645, 3, 647, 3, 672, 5, 673, 5, 674, 4, 677, 3, 678, 4, 679, 3, 680, 13, 681, 13, 682, 12, 685, 14, 686, 12, 687, 14, 712, 20, 714, 18, 809, 21, 813, 23, 840, 20, 841, 21, 1198, 19, 1199, 22, 1226, 18, 1230, 19, 1325, 23, 1327, 22, 1352, 15, 1353, 17, 1354, 15, 1357, 17, 1358, 16, 1359, 16, 1360, 11, 1361, 10, 1362, 11, 1365, 10, 1366, 9, 1367, 9, 1392, 11, 1394, 11, 1489, 10, 1493, 10, 1520, 8, 1521, 8, 1878, 9, 1879, 9, 1906, 7, 1910, 7, 2005, 6, 2007, 6, 2032, 8, 2033, 8, 2034, 7, 2037, 6, 2038, 7, 2039, 6 };

            Contribution3[] contributions3D = new Contribution3[p3D.Length / 9];
            for (int i = 0; i < p3D.Length; i += 9)
            {
                int[]         baseSet = base3D[p3D[i]];
                Contribution3 previous = null, current = null;
                for (int k = 0; k < baseSet.Length; k += 4)
                {
                    current = new Contribution3(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
                    if (previous == null)
                    {
                        contributions3D[i / 9] = current;
                    }
                    else
                    {
                        previous.next = current;
                    }
                    previous = current;
                }
                current.next      = new Contribution3(p3D[i + 1], p3D[i + 2], p3D[i + 3], p3D[i + 4]);
                current.next.next = new Contribution3(p3D[i + 5], p3D[i + 6], p3D[i + 7], p3D[i + 8]);
            }

            LOOKUP_3D = new Contribution3[2048];
            for (int i = 0; i < lookupPairs3D.Length; i += 2)
            {
                LOOKUP_3D[lookupPairs3D[i]] = contributions3D[lookupPairs3D[i + 1]];
            }
        }
Beispiel #10
0
        /*
         * Multi-eval
         */

        //2D OpenSimplex noise Multi-eval (KdotJPG)
        public static void noise(double x, double y, NoiseInstance2[] instances, double[] results)
        {
            //Get points for A2 lattice
            double s = STRETCH_2D * (x + y);
            double xs = x + s, ys = y + s;

            //Get base points and offsets
            int    xsb = fastFloor(xs), ysb = fastFloor(ys);
            double xsi = xs - xsb, ysi = ys - ysb;

            //Index to point list
            int a     = (int)(ysi - xsi + 1);
            int index =
                (a << 2) |
                (int)(xsi + ysi / 2.0 + a / 2.0) << 3 |
                    (int)(ysi + xsi / 2.0 + 1.0 / 2.0 - a / 2.0) << 4;

            //Get unskewed offsets.
            double ssi = (xsi + ysi) * SQUISH_2D;
            double xi = xsi + ssi, yi = ysi + ssi;

            //Point contributions
            for (int i = 0; i < 4; i++)
            {
                LatticePoint2D c = LOOKUP_2D[index + i];

                double dx = xi + c.dx, dy = yi + c.dy;
                double attn = 2.0 - dx * dx - dy * dy;
                if (attn <= 0)
                {
                    continue;
                }
                double attnSq = attn * attn;

                int pxm = (xsb + c.xsv) & 1023, pym = (ysb + c.ysv) & 1023;
                foreach (NoiseInstance2 instance in instances)
                {
                    int    gi_p = instance.noise.perm[pxm] ^ pym;
                    int    gi = instance.noise.perm2D[gi_p];
                    double gx = GRADIENTS_2D[gi + 0], gy = GRADIENTS_2D[gi + 1];
                    double extrapolation = gx * dx + gy * dy;

                    if (instance.valueIndex >= 0)
                    {
                        results[instance.valueIndex] += attnSq * attnSq * extrapolation;
                    }
                    if ((instance.ddxIndex & instance.ddyIndex) >= 0)
                    {
                        if (instance.ddxIndex >= 0)
                        {
                            results[instance.ddxIndex] += (gx * attn - 8 * dx * extrapolation) * attnSq * attn;
                        }
                        if (instance.ddyIndex >= 0)
                        {
                            results[instance.ddyIndex] += (gy * attn - 8 * dy * extrapolation) * attnSq * attn;
                        }
                    }
                    if ((instance.sph2xIndex & instance.sph2yIndex) >= 0)
                    {
                        int gi_sph2 = instance.noise.perm2D_sph2[gi_p];
                        if (instance.sph2xIndex >= 0)
                        {
                            results[instance.sph2xIndex] += attnSq * attnSq * extrapolation * GRADIENTS_SPH2[gi_sph2 + 0];
                        }
                        if (instance.sph2yIndex >= 0)
                        {
                            results[instance.sph2yIndex] += attnSq * attnSq * extrapolation * GRADIENTS_SPH2[gi_sph2 + 1];
                        }
                    }
                }
            }
        }
Beispiel #11
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];
            }
        }
        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];
            }
        }
        static SimplexPerlin()
        {
            //2D (KdotJPG)
            _lookup2D = new LatticePoint2D[8 * 4];

            for (int i = 0; i < 8; i++)
            {
                int i1, j1, i2, j2;
                if ((i & 1) == 0)
                {
                    if ((i & 2) == 0)
                    {
                        i1 = 0;
                        j1 = 0;
                    }
                    else
                    {
                        i1 = 2;
                        j1 = 0;
                    }

                    if ((i & 4) == 0)
                    {
                        i2 = 1;
                        j2 = -1;
                    }
                    else
                    {
                        i2 = 1;
                        j2 = 1;
                    }
                }
                else
                {
                    if ((i & 2) == 0)
                    {
                        i1 = -1;
                        j1 = 1;
                    }
                    else
                    {
                        i1 = 1;
                        j1 = 1;
                    }

                    if ((i & 4) == 0)
                    {
                        i2 = 0;
                        j2 = 0;
                    }
                    else
                    {
                        i2 = 0;
                        j2 = 2;
                    }
                }

                _lookup2D[i * 4]     = new LatticePoint2D(1, 0);
                _lookup2D[i * 4 + 1] = new LatticePoint2D(0, 1);
                _lookup2D[i * 4 + 2] = new LatticePoint2D(i1, j1);
                _lookup2D[i * 4 + 3] = new LatticePoint2D(i2, j2);
            }
        }