AccidentalNoise.Noise.SimplexNoise C# (CSharp) Метод

SimplexNoise() публичный статический Метод

public static SimplexNoise ( Double x, Double y, Double z, Double w, Double u, Double v, Int32 seed, InterpolationDelegate interp ) : Double
x Double
y Double
z Double
w Double
u Double
v Double
seed System.Int32
interp InterpolationDelegate
Результат Double
        public static Double SimplexNoise(Double x, Double y, Double z, Double w, Double u, Double v, Int32 seed, InterpolationDelegate interp)
        {
            // Skew
            var f4 = (Math.Sqrt(7.0) - 1.0) / 6.0;

            // Unskew
            var g4 = f4/(1.0 + 6.0*f4);

            var sideLength = Math.Sqrt(6.0)/(6.0*f4 + 1.0);
            var a = Math.Sqrt((sideLength * sideLength) - ((sideLength / 2.0) * (sideLength / 2.0)));
            var cornerFace = Math.Sqrt(a * a + (a / 2.0) * (a / 2.0));

            var cornerFaceSqrd = cornerFace * cornerFace;

            var valueScaler = Math.Pow(5.0, -0.5);
            valueScaler *= Math.Pow(5.0, -3.5) * 100 + 13;

            var loc = new[] { x, y, z, w, u, v };
            var s = 0.00;
            for (var c = 0; c < 6; ++c)
                s += loc[c];
            s *= f4;

            var skewLoc = new[]{
                FastFloor(x + s), FastFloor(y + s), FastFloor(z + s), 
                FastFloor(w + s), FastFloor(u + s), FastFloor(v + s)
            };
            var intLoc = new[]{
                FastFloor(x + s), FastFloor(y + s), FastFloor(z + s),
                FastFloor(w + s), FastFloor(u + s), FastFloor(v + s)
            };
            var unskew = 0.0;
            for (var c = 0; c < 6; ++c) 
                unskew += skewLoc[c];
            unskew *= g4;

            var cellDist = new[]
            {
                loc[0] - skewLoc[0] + unskew, loc[1] - skewLoc[1] + unskew,
                loc[2] - skewLoc[2] + unskew, loc[3] - skewLoc[3] + unskew,
                loc[4] - skewLoc[4] + unskew, loc[5] - skewLoc[5] + unskew
            };
            var distOrder = new[] { 0, 1, 2, 3, 4, 5 };
            SortBy6(cellDist, distOrder);

            var newDistOrder = new[] 
            {
                -1, distOrder[0], distOrder[1], distOrder[2], distOrder[3], distOrder[4], distOrder[5]
            };

            var n = 0.00;
            var skewOffset = 0.00;

            for (var c = 0; c < 7; ++c)
            {
                var i = newDistOrder[c];
                if (i != -1) 
                    intLoc[i] += 1;

                var uu = new Double[6];
                for (var d = 0; d < 6; ++d)
                {
                    uu[d] = cellDist[d] - (intLoc[d] - skewLoc[d]) + skewOffset;
                }

                var t = cornerFaceSqrd;

                for (var d = 0; d < 6; ++d)
                {
                    t -= uu[d]*uu[d];
                }

                if (t > 0.0)
                {
                    var h = HashCoordinates(intLoc[0], intLoc[1], intLoc[2], intLoc[3], intLoc[4], intLoc[5], seed);
                    var gr = 0.00;

                    gr += NoiseLookupTable.Gradient6D[h, 0]*uu[0];
                    gr += NoiseLookupTable.Gradient6D[h, 1]*uu[1];
                    gr += NoiseLookupTable.Gradient6D[h, 2]*uu[2];
                    gr += NoiseLookupTable.Gradient6D[h, 3]*uu[3];
                    gr += NoiseLookupTable.Gradient6D[h, 4]*uu[4];
                    gr += NoiseLookupTable.Gradient6D[h, 5]*uu[5];

                    n += gr*t*t*t*t;
                }
                skewOffset += g4;
            }
            n *= valueScaler;
            return n;
        }

Same methods

Noise::SimplexNoise ( Double x, Double y, Double z, Double w, Int32 seed, InterpolationDelegate interp ) : Double
Noise::SimplexNoise ( Double x, Double y, Double z, Int32 seed, InterpolationDelegate interp ) : Double
Noise::SimplexNoise ( Double x, Double y, Int32 seed, InterpolationDelegate interp ) : Double