Skip to content

Instantly share code, notes, and snippets.

@JamieShelley
Forked from digitalshadow/OpenSimplexNoise.cs
Created December 1, 2016 12:07
Show Gist options
  • Save JamieShelley/3687780494041e3e0e06f4e9a357cae9 to your computer and use it in GitHub Desktop.
Save JamieShelley/3687780494041e3e0e06f4e9a357cae9 to your computer and use it in GitHub Desktop.

Revisions

  1. @digitalshadow digitalshadow revised this gist Feb 7, 2015. 1 changed file with 115 additions and 646 deletions.
    761 changes: 115 additions & 646 deletions OpenSimplexNoise.cs
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    /* OpenSimplex Noise in C#
    * Ported from https://gist.github.com/KdotJPG/b1270127455a94ac5d19
    * and heavily refactored to improve performance. The main difference is that once the
    * bit flags are determined, the result is pulled from a lookup table, saving the time
    * used deciphering the bit flags again. */
    * and heavily refactored to improve performance. */

    using System;
    using System.Collections.Generic;
    @@ -68,94 +66,83 @@ public class OpenSimplexNoise
    -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
    };

    private static Contribution2[][] contributions2D;
    private static Contribution3[][] contributions3D;
    private static Contribution4[][] contributions4D;

    private static Contribution2[] lookup2D;
    private static Contribution3[] lookup3D;
    private static Contribution4[] lookup4D;
    static OpenSimplexNoise()
    {
    var base2D = new int[][]
    {
    new int[] { 1, 1, 0, 1, 0, 1, 0, 0, 0 },
    new int[] { 1, 1, 0, 1, 0, 1, 2, 1, 1 }
    };
    var permutations2D = new int[][]
    {
    new int[] { 0, 0, 1, -1, 0, -1, 1, 2, 1, 1 },
    new int[] { 1, 2, 2, 0, 2, 0, 2, 0, 0, 0 }
    };
    var p2D = new int[] { 0, 0, 1, -1, 0, 0, -1, 1, 0, 2, 1, 1, 1, 2, 2, 0, 1, 2, 0, 2, 1, 0, 0, 0 };
    var lookupPairs2D = new int[] { 0, 1, 1, 0, 4, 1, 17, 0, 20, 2, 21, 2, 22, 5, 23, 5, 26, 4, 39, 3, 42, 4, 43, 3 };

    contributions2D = new Contribution2[base2D.Length][];
    for (int i = 0; i < base2D.Length; i++)
    var contributions2D = new Contribution2[p2D.Length / 4];
    for (int i = 0; i < p2D.Length; i += 4)
    {
    var permutations = permutations2D[i];
    var set = base2D[permutations[0]];
    var contributions = new Contribution2[permutations.Length / 3];

    for (int j = 1; j < permutations.Length; j += 3)
    var baseSet = base2D[p2D[i]];
    Contribution2 previous = null, current = null;
    for (int k = 0; k < baseSet.Length; k += 3)
    {
    Contribution2 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 3)
    current = new Contribution2(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
    if (previous == null)
    {
    current = new Contribution2(set[k], set[k + 1], set[k + 2]);
    if (previous == null)
    {
    contributions[j / 3] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    contributions2D[i / 4] = current;
    }
    current.Next = new Contribution2(permutations[j], permutations[j + 1], permutations[j + 2]);
    else
    {
    previous.Next = current;
    }
    previous = current;
    }
    contributions2D[i] = contributions;
    current.Next = new Contribution2(p2D[i + 1], p2D[i + 2], p2D[i + 3]);
    }

    lookup2D = new Contribution2[64];
    for (var i = 0; i < lookupPairs2D.Length; i += 2)
    {
    lookup2D[lookupPairs2D[i]] = contributions2D[lookupPairs2D[i + 1]];
    }


    var 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 }
    };
    var permutations3D = new int[][]
    {
    new int[] { 0 ,0, -1, 0, 0, 0, 0, -1, -1, 0, 1, -1, 0, 0, 1, 0, -1, 0, -1, 1, 0, 0, 0, 1, -1, 0, 1, 1, 0, 0, 1, 1, -1, 0, -1, 0, 1, 0, 0, -1, 1, 0, 1, -1, 1, 0, 1,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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 };

    contributions3D = new Contribution3[permutations3D.Length][];
    for (int i = 0; i < permutations3D.Length; i++)
    var contributions3D = new Contribution3[p3D.Length / 9];
    for (int i = 0; i < p3D.Length; i += 9)
    {
    var permutations = permutations3D[i];
    var set = base3D[permutations[0]];
    var contributions = new Contribution3[permutations.Length / 8];

    for (int j = 1; j < permutations.Length; j += 8)
    var baseSet = base3D[p3D[i]];
    Contribution3 previous = null, current = null;
    for (int k = 0; k < baseSet.Length; k += 4)
    {
    Contribution3 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 4)
    current = new Contribution3(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
    if (previous == null)
    {
    current = new Contribution3(set[k], set[k + 1], set[k + 2], set[k + 3]);
    if (previous == null)
    {
    contributions[j / 8] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    contributions3D[i / 9] = current;
    }
    current.Next = new Contribution3(permutations[j], permutations[j + 1], permutations[j + 2], permutations[j + 3]);
    current.Next.Next = new Contribution3(permutations[j + 4], permutations[j + 5], permutations[j + 6], permutations[j + 7]);
    else
    {
    previous.Next = current;
    }
    previous = current;
    }
    contributions3D[i] = contributions;
    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]);
    }

    lookup3D = new Contribution3[2048];
    for (var i = 0; i < lookupPairs3D.Length; i += 2)
    {
    lookup3D[lookupPairs3D[i]] = contributions3D[lookupPairs3D[i + 1]];
    }

    var base4D = new int[][]
    @@ -165,49 +152,35 @@ static OpenSimplexNoise()
    new int[] { 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 2, 1, 1, 0, 0, 2, 1, 0, 1, 0, 2, 1, 0, 0, 1, 2, 0, 1, 1, 0, 2, 0, 1, 0, 1, 2, 0, 0, 1, 1 },
    new int[] { 3, 1, 1, 1, 0, 3, 1, 1, 0, 1, 3, 1, 0, 1, 1, 3, 0, 1, 1, 1, 2, 1, 1, 0, 0, 2, 1, 0, 1, 0, 2, 1, 0, 0, 1, 2, 0, 1, 1, 0, 2, 0, 1, 0, 1, 2, 0, 0, 1, 1 }
    };

    var permutations4D = new int[][]
    {
    new int[] { 0 ,0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, -1, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 0, 1, 0, 0, -1, 0, -1, 1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, -1, 0, -1, 0, 1, 0, 0, 0, -1, 1, 0, 0, 0, 0, 1, -1, 0, 1, -1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, -1, 0, -1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, -1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, -1, 0, -1, 0, 0, 1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 1, 0, 1, -1, 0, 1, 0, 1, 0, -1, 1, 0, 1, 0, 0, 1, 0, -1, 1, 0, 1, 0, 0, 1, -1, 1, 0, 0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, 2, -1, 1, 1, 1, 3, 2, 0, 1, 1, 3, 1, 0, 2, 2, 2, -1, 1, 1, 1, 3, 0, 2, 1, 1, 3, 0, 1, 2, 2, 2, -1, 1, 1, 1, 3, 2, 1, 1, 1, 3, 1, 2, 2, 2, 2, -1, 1, 1, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 1, 1, 1, -1, 3, 2, 0, 0, 0, 3, 1, 0, 0, 0, 2, 1, 1, 1, -1, 3, 0, 2, 0, 0, 3, 0, 1, 0, 0, 2, 1, 1, 1, -1, 3, 2, 1, 0, 0, 3, 1, 2, 0, 0, 2, 1, 1, 1, -1, 3, 0, 0, 2, 0, 3, 0, 0, 1, 0, 2, 1, 1, 1, -1, 3, 2, 0, 1, 0, 3, 1, 0, 2, 0, 2, 1, 1, 1, -1, 3, 0, 2, 1, 0, 3, 0, 1, 2, 0, 2, 1, 1, 1, -1, 3, 2, 1, 1, 0, 3, 1, 2, 2, 0, 2, 1, 1, 1, -1, 3, 0, 0, 0, 1, 3, 0, 0, 0, 2, 2, 1, 1, 1, -1, 3, 2, 0, 0, 1, 3, 1, 0, 0, 2, 2, 1, 1, 1, -1, 3, 0, 2, 0, 1, 3, 0, 1, 0, 2, 2, 1, 1, 1, -1, 3, 2, 1, 0, 1, 3, 1, 2, 0, 2, 2, 1, 1, 1, -1, 3, 0, 0, 2, 1, 3, 0, 0, 1, 2, 2, 1, 1, 1, -1, 3, 2, 0, 1, 1, 3, 1, 0, 2, 2, 2, 1, 1, 1, -1, 3, 0, 2, 1, 1, 3, 0, 1, 2, 2, 2, 1, 1, 1, -1, 3, 2, 1, 1, 1, 3, 1, 2, 2, 2, 2, 1, 1, 1, -1 }
    };

    contributions4D = new Contribution4[permutations4D.Length][];
    for (int i = 0; i < permutations4D.Length; i++)
    var p4D = new int[] { 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 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390, 1, 16391, 1, 16406, 1, 16407, 1, 16422, 1, 16423, 1, 16438, 1, 16439, 1, 16642, 8, 16646, 8, 16658, 8, 16662, 8, 18437, 6, 18439, 6, 18469, 6, 18471, 6, 18688, 9, 18689, 9, 18690, 8, 18693, 6, 18694, 8, 18695, 6, 18696, 9, 18697, 9, 18706, 8, 18710, 8, 18725, 6, 18727, 6, 131128, 0, 131129, 0, 131130, 0, 131131, 0, 131132, 0, 131133, 0, 131134, 0, 131135, 0, 131352, 7, 131354, 7, 131384, 7, 131386, 7, 133161, 5, 133165, 5, 133177, 5, 133181, 5, 133376, 9, 133377, 9, 133384, 9, 133385, 9, 133400, 7, 133402, 7, 133417, 5, 133421, 5, 133432, 7, 133433, 5, 133434, 7, 133437, 5, 147510, 4, 147511, 4, 147518, 4, 147519, 4, 147714, 8, 147718, 8, 147730, 8, 147734, 8, 147736, 7, 147738, 7, 147766, 4, 147767, 4, 147768, 7, 147770, 7, 147774, 4, 147775, 4, 149509, 6, 149511, 6, 149541, 6, 149543, 6, 149545, 5, 149549, 5, 149558, 4, 149559, 4, 149561, 5, 149565, 5, 149566, 4, 149567, 4, 149760, 9, 149761, 9, 149762, 8, 149765, 6, 149766, 8, 149767, 6, 149768, 9, 149769, 9, 149778, 8, 149782, 8, 149784, 7, 149786, 7, 149797, 6, 149799, 6, 149801, 5, 149805, 5, 149814, 4, 149815, 4, 149816, 7, 149817, 5, 149818, 7, 149821, 5, 149822, 4, 149823, 4, 149824, 37, 149825, 37, 149826, 36, 149829, 34, 149830, 36, 149831, 34, 149832, 37, 149833, 37, 149842, 36, 149846, 36, 149848, 35, 149850, 35, 149861, 34, 149863, 34, 149865, 33, 149869, 33, 149878, 32, 149879, 32, 149880, 35, 149881, 33, 149882, 35, 149885, 33, 149886, 32, 149887, 32, 150080, 49, 150082, 48, 150088, 49, 150098, 48, 150104, 47, 150106, 47, 151873, 46, 151877, 45, 151881, 46, 151909, 45, 151913, 44, 151917, 44, 152128, 49, 152129, 46, 152136, 49, 152137, 46, 166214, 43, 166215, 42, 166230, 43, 166247, 42, 166262, 41, 166263, 41, 166466, 48, 166470, 43, 166482, 48, 166486, 43, 168261, 45, 168263, 42, 168293, 45, 168295, 42, 168512, 31, 168513, 28, 168514, 31, 168517, 28, 168518, 25, 168519, 25, 280952, 40, 280953, 39, 280954, 40, 280957, 39, 280958, 38, 280959, 38, 281176, 47, 281178, 47, 281208, 40, 281210, 40, 282985, 44, 282989, 44, 283001, 39, 283005, 39, 283208, 30, 283209, 27, 283224, 30, 283241, 27, 283256, 22, 283257, 22, 297334, 41, 297335, 41, 297342, 38, 297343, 38, 297554, 29, 297558, 24, 297562, 29, 297590, 24, 297594, 21, 297598, 21, 299365, 26, 299367, 23, 299373, 26, 299383, 23, 299389, 20, 299391, 20, 299584, 31, 299585, 28, 299586, 31, 299589, 28, 299590, 25, 299591, 25, 299592, 30, 299593, 27, 299602, 29, 299606, 24, 299608, 30, 299610, 29, 299621, 26, 299623, 23, 299625, 27, 299629, 26, 299638, 24, 299639, 23, 299640, 22, 299641, 22, 299642, 21, 299645, 20, 299646, 21, 299647, 20, 299648, 61, 299649, 60, 299650, 61, 299653, 60, 299654, 59, 299655, 59, 299656, 58, 299657, 57, 299666, 55, 299670, 54, 299672, 58, 299674, 55, 299685, 52, 299687, 51, 299689, 57, 299693, 52, 299702, 54, 299703, 51, 299704, 56, 299705, 56, 299706, 53, 299709, 50, 299710, 53, 299711, 50, 299904, 61, 299906, 61, 299912, 58, 299922, 55, 299928, 58, 299930, 55, 301697, 60, 301701, 60, 301705, 57, 301733, 52, 301737, 57, 301741, 52, 301952, 79, 301953, 79, 301960, 76, 301961, 76, 316038, 59, 316039, 59, 316054, 54, 316071, 51, 316086, 54, 316087, 51, 316290, 78, 316294, 78, 316306, 73, 316310, 73, 318085, 77, 318087, 77, 318117, 70, 318119, 70, 318336, 79, 318337, 79, 318338, 78, 318341, 77, 318342, 78, 318343, 77, 430776, 56, 430777, 56, 430778, 53, 430781, 50, 430782, 53, 430783, 50, 431000, 75, 431002, 72, 431032, 75, 431034, 72, 432809, 74, 432813, 69, 432825, 74, 432829, 69, 433032, 76, 433033, 76, 433048, 75, 433065, 74, 433080, 75, 433081, 74, 447158, 71, 447159, 68, 447166, 71, 447167, 68, 447378, 73, 447382, 73, 447386, 72, 447414, 71, 447418, 72, 447422, 71, 449189, 70, 449191, 70, 449197, 69, 449207, 68, 449213, 69, 449215, 68, 449408, 67, 449409, 67, 449410, 66, 449413, 64, 449414, 66, 449415, 64, 449416, 67, 449417, 67, 449426, 66, 449430, 66, 449432, 65, 449434, 65, 449445, 64, 449447, 64, 449449, 63, 449453, 63, 449462, 62, 449463, 62, 449464, 65, 449465, 63, 449466, 65, 449469, 63, 449470, 62, 449471, 62, 449472, 19, 449473, 19, 449474, 18, 449477, 16, 449478, 18, 449479, 16, 449480, 19, 449481, 19, 449490, 18, 449494, 18, 449496, 17, 449498, 17, 449509, 16, 449511, 16, 449513, 15, 449517, 15, 449526, 14, 449527, 14, 449528, 17, 449529, 15, 449530, 17, 449533, 15, 449534, 14, 449535, 14, 449728, 19, 449729, 19, 449730, 18, 449734, 18, 449736, 19, 449737, 19, 449746, 18, 449750, 18, 449752, 17, 449754, 17, 449784, 17, 449786, 17, 451520, 19, 451521, 19, 451525, 16, 451527, 16, 451528, 19, 451529, 19, 451557, 16, 451559, 16, 451561, 15, 451565, 15, 451577, 15, 451581, 15, 451776, 19, 451777, 19, 451784, 19, 451785, 19, 465858, 18, 465861, 16, 465862, 18, 465863, 16, 465874, 18, 465878, 18, 465893, 16, 465895, 16, 465910, 14, 465911, 14, 465918, 14, 465919, 14, 466114, 18, 466118, 18, 466130, 18, 466134, 18, 467909, 16, 467911, 16, 467941, 16, 467943, 16, 468160, 13, 468161, 13, 468162, 13, 468163, 13, 468164, 13, 468165, 13, 468166, 13, 468167, 13, 580568, 17, 580570, 17, 580585, 15, 580589, 15, 580598, 14, 580599, 14, 580600, 17, 580601, 15, 580602, 17, 580605, 15, 580606, 14, 580607, 14, 580824, 17, 580826, 17, 580856, 17, 580858, 17, 582633, 15, 582637, 15, 582649, 15, 582653, 15, 582856, 12, 582857, 12, 582872, 12, 582873, 12, 582888, 12, 582889, 12, 582904, 12, 582905, 12, 596982, 14, 596983, 14, 596990, 14, 596991, 14, 597202, 11, 597206, 11, 597210, 11, 597214, 11, 597234, 11, 597238, 11, 597242, 11, 597246, 11, 599013, 10, 599015, 10, 599021, 10, 599023, 10, 599029, 10, 599031, 10, 599037, 10, 599039, 10, 599232, 13, 599233, 13, 599234, 13, 599235, 13, 599236, 13, 599237, 13, 599238, 13, 599239, 13, 599240, 12, 599241, 12, 599250, 11, 599254, 11, 599256, 12, 599257, 12, 599258, 11, 599262, 11, 599269, 10, 599271, 10, 599272, 12, 599273, 12, 599277, 10, 599279, 10, 599282, 11, 599285, 10, 599286, 11, 599287, 10, 599288, 12, 599289, 12, 599290, 11, 599293, 10, 599294, 11, 599295, 10 };
    var contributions4D = new Contribution4[p4D.Length / 16];
    for (int i = 0; i < p4D.Length; i += 16)
    {
    var permutations = permutations4D[i];
    var set = base4D[permutations[0]];
    var contributions = new Contribution4[permutations.Length / 15];

    for (int j = 1; j < permutations.Length; j += 15)
    var baseSet = base4D[p4D[i]];
    Contribution4 previous = null, current = null;
    for (int k = 0; k < baseSet.Length; k += 5)
    {
    Contribution4 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 5)
    current = new Contribution4(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]);
    if (previous == null)
    {
    contributions4D[i / 16] = current;
    }
    else
    {
    current = new Contribution4(set[k], set[k + 1], set[k + 2], set[k + 3], set[k + 4]);
    if (previous == null)
    {
    contributions[j / 15] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    previous.Next = current;
    }
    current.Next = new Contribution4(permutations[j], permutations[j + 1], permutations[j + 2], permutations[j + 3], permutations[j + 4]);
    current.Next.Next = new Contribution4(permutations[j + 5], permutations[j + 6], permutations[j + 7], permutations[j + 8], permutations[j + 9]);
    current.Next.Next.Next = new Contribution4(permutations[j + 10], permutations[j + 11], permutations[j + 12], permutations[j + 13], permutations[j + 14]);
    previous = current;
    }
    contributions4D[i] = contributions;
    current.Next = new Contribution4(p4D[i + 1], p4D[i + 2], p4D[i + 3], p4D[i + 4], p4D[i + 5]);
    current.Next.Next = new Contribution4(p4D[i + 6], p4D[i + 7], p4D[i + 8], p4D[i + 9], p4D[i + 10]);
    current.Next.Next.Next = new Contribution4(p4D[i + 11], p4D[i + 12], p4D[i + 13], p4D[i + 14], p4D[i + 15]);
    }

    lookup4D = new Contribution4[1048576];
    for (var i = 0; i < lookupPairs4D.Length; i += 2)
    {
    lookup4D[lookupPairs4D[i]] = contributions4D[lookupPairs4D[i + 1]];
    }
    }

    @@ -263,56 +236,21 @@ public double Evaluate(double x, double y)
    var ysb = FastFloor(ys);

    var squishOffset = (xsb + ysb) * SQUISH_2D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;

    var dx0 = x - xb;
    var dy0 = y - yb;
    var dx0 = x - (xsb + squishOffset);
    var dy0 = y - (ysb + squishOffset);

    var xins = xs - xsb;
    var yins = ys - ysb;

    Contribution2 c;

    var inSum = xins + yins;
    if (inSum <= 1)
    {
    var zins = 1 - inSum;
    if (zins > xins || zins > yins)
    {
    if (xins > yins)
    {
    c = contributions2D[0][0];
    }
    else
    {
    c = contributions2D[0][1];
    }
    }
    else
    {
    c = contributions2D[0][2];
    }
    }
    else
    {
    var zins = 2 - inSum;
    if (zins < xins || zins < yins)
    {
    if (xins > yins)
    {
    c = contributions2D[1][0];
    }
    else
    {
    c = contributions2D[1][1];
    }
    }
    else
    {
    c = contributions2D[1][2];
    }
    }

    var hash =
    (int)(xins - yins + 1) |
    (int)(inSum) << 1 |
    (int)(inSum + yins) << 2 |
    (int)(inSum + xins) << 4;

    var c = lookup2D[hash];

    var value = 0.0;
    while (c != null)
    @@ -336,7 +274,6 @@ public double Evaluate(double x, double y)
    return value * NORM_2D;
    }


    public double Evaluate(double x, double y, double z)
    {
    var stretchOffset = (x + y + z) * STRETCH_3D;
    @@ -349,155 +286,26 @@ public double Evaluate(double x, double y, double z)
    var zsb = FastFloor(zs);

    var squishOffset = (xsb + ysb + zsb) * SQUISH_3D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;

    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;
    var dx0 = x - (xsb + squishOffset);
    var dy0 = y - (ysb + squishOffset);
    var dz0 = z - (zsb + squishOffset);

    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;

    Contribution3 c;
    var inSum = xins + yins + zins;
    if (inSum <= 1)
    {
    var aPoint = 0x01;
    var aScore = xins;
    var bPoint = 0x02;
    var bScore = yins;
    if (aScore >= bScore && zins > bScore)
    {
    bScore = zins;
    bPoint = 0x04;
    }
    else if (aScore < bScore && zins > aScore)
    {
    aScore = zins;
    aPoint = 0x04;
    }

    var wins = 1 - inSum;
    if (wins > aScore || wins > bScore)
    {
    c = contributions3D[0][bScore > aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions3D[1][aPoint | bPoint];
    }
    }
    else if (inSum >= 2)
    {
    var aPoint = 0x06;
    var aScore = xins;
    var bPoint = 0x05;
    var bScore = yins;
    if (aScore <= bScore && zins < bScore)
    {
    bScore = zins;
    bPoint = 0x03;
    }
    else if (aScore > bScore && zins < aScore)
    {
    aScore = zins;
    aPoint = 0x03;
    }
    var hash =
    (int)(yins - zins + 1) |
    (int)(xins - yins + 1) << 1 |
    (int)(xins - zins + 1) << 2 |
    (int)inSum << 3 |
    (int)(inSum + zins) << 5 |
    (int)(inSum + yins) << 7 |
    (int)(inSum + xins) << 9;

    var wins = 3 - inSum;
    if (wins < aScore || wins < bScore)
    {
    c = contributions3D[2][bScore < aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions3D[3][aPoint & bPoint];
    }
    }
    else
    {
    byte aPoint;
    bool aIsFurtherSide;
    byte bPoint;
    bool bIsFurtherSide;

    var p1 = xins + yins;
    if (p1 > 1)
    {
    p1 = p1 - 1;
    aPoint = 0x03;
    aIsFurtherSide = true;
    }
    else
    {
    p1 = 1 - p1;
    aPoint = 0x04;
    aIsFurtherSide = false;
    }

    var p2 = xins + zins;
    if (p2 > 1)
    {
    p2 = p2 - 1;
    bPoint = 0x05;
    bIsFurtherSide = true;
    }
    else
    {
    p2 = 1 - p2;
    bPoint = 0x02;
    bIsFurtherSide = false;
    }

    var p3 = yins + zins;
    if (p3 > 1)
    {
    p3 = p3 - 1;
    if (p1 <= p2 && p1 < p3)
    {
    aPoint = 0x06;
    aIsFurtherSide = true;
    }
    else if (p1 > p2 && p2 < p3)
    {
    bPoint = 0x06;
    bIsFurtherSide = true;
    }
    }
    else
    {
    p3 = 1 - p3;
    if (p1 <= p2 && p1 < p3)
    {
    aPoint = 0x01;
    aIsFurtherSide = false;
    }
    else if (p1 > p2 && p2 < p3)
    {
    bPoint = 0x01;
    bIsFurtherSide = false;
    }
    }

    if (aIsFurtherSide == bIsFurtherSide)
    {
    c = contributions3D[4][aIsFurtherSide ? ((aPoint & bPoint) & 0x03) | 0x4 : (aPoint | bPoint) & 0x03];
    }
    else
    {
    if (aIsFurtherSide)
    {
    c = contributions3D[5][((aPoint & 0x03) << 2) | (bPoint & 0x03)];
    }
    else
    {
    c = contributions3D[5][((bPoint & 0x03) << 2) | (aPoint & 0x03)];
    }
    }
    }
    var c = lookup3D[hash];

    var value = 0.0;
    while (c != null)
    @@ -538,370 +346,32 @@ public double Evaluate(double x, double y, double z, double w)
    var wsb = FastFloor(ws);

    var squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;
    var wb = wsb + squishOffset;

    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;
    var dw0 = w - wb;
    var dx0 = x - (xsb + squishOffset);
    var dy0 = y - (ysb + squishOffset);
    var dz0 = z - (zsb + squishOffset);
    var dw0 = w - (wsb + squishOffset);

    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;
    var wins = ws - wsb;

    double aScore, bScore;
    int aPoint, bPoint;

    Contribution4 c;

    var inSum = xins + yins + zins + wins;
    if (inSum <= 1)
    {
    aPoint = 0x01;
    aScore = xins;
    bPoint = 0x02;
    bScore = yins;
    if (aScore >= bScore && zins > bScore)
    {
    bScore = zins;
    bPoint = 0x04;
    }
    else if (aScore < bScore && zins > aScore)
    {
    aScore = zins;
    aPoint = 0x04;
    }
    if (aScore >= bScore && wins > bScore)
    {
    bScore = wins;
    bPoint = 0x08;
    }
    else if (aScore < bScore && wins > aScore)
    {
    aScore = wins;
    aPoint = 0x08;
    }
    var uins = 1 - inSum;
    if (uins > aScore || uins > bScore)
    {
    c = contributions4D[0][bScore > aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions4D[1][aPoint | bPoint];
    }
    }
    else if (inSum >= 3)
    {
    aPoint = 0x0E;
    aScore = xins;
    bPoint = 0x0D;
    bScore = yins;
    if (aScore <= bScore && zins < bScore)
    {
    bScore = zins;
    bPoint = 0x0B;
    }
    else if (aScore > bScore && zins < aScore)
    {
    aScore = zins;
    aPoint = 0x0B;
    }
    if (aScore <= bScore && wins < bScore)
    {
    bScore = wins;
    bPoint = 0x07;
    }
    else if (aScore > bScore && wins < aScore)
    {
    aScore = wins;
    aPoint = 0x07;
    }

    var uins = 4 - inSum;
    if (uins < aScore || uins < bScore)
    {
    c = contributions4D[2][bScore < aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions4D[3][aPoint & bPoint];
    }
    }
    else if (inSum <= 2)
    {
    var aIsBiggerSide = true;
    var bIsBiggerSide = true;

    if (xins + yins > zins + wins)
    {
    aScore = xins + yins;
    aPoint = 0x03;
    }
    else
    {
    aScore = zins + wins;
    aPoint = 0x0C;
    }

    if (xins + zins > yins + wins)
    {
    bScore = xins + zins;
    bPoint = 0x05;
    }
    else
    {
    bScore = yins + wins;
    bPoint = 0x0A;
    }

    if (xins + wins > yins + zins)
    {
    var score = xins + wins;
    if (aScore >= bScore && score > bScore)
    {
    bScore = score;
    bPoint = 0x09;
    }
    else if (aScore < bScore && score > aScore)
    {
    aScore = score;
    aPoint = 0x09;
    }
    }
    else
    {
    var score = yins + zins;
    if (aScore >= bScore && score > bScore)
    {
    bScore = score;
    bPoint = 0x06;
    }
    else if (aScore < bScore && score > aScore)
    {
    aScore = score;
    aPoint = 0x06;
    }
    }

    var p1 = 2 - inSum + xins;
    if (aScore >= bScore && p1 > bScore)
    {
    bScore = p1;
    bPoint = 0x01;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p1 > aScore)
    {
    aScore = p1;
    aPoint = 0x01;
    aIsBiggerSide = false;
    }

    var p2 = 2 - inSum + yins;
    if (aScore >= bScore && p2 > bScore)
    {
    bScore = p2;
    bPoint = 0x02;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p2 > aScore)
    {
    aScore = p2;
    aPoint = 0x02;
    aIsBiggerSide = false;
    }

    var p3 = 2 - inSum + zins;
    if (aScore >= bScore && p3 > bScore)
    {
    bScore = p3;
    bPoint = 0x04;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p3 > aScore)
    {
    aScore = p3;
    aPoint = 0x04;
    aIsBiggerSide = false;
    }

    var p4 = 2 - inSum + wins;
    if (aScore >= bScore && p4 > bScore)
    {
    bScore = p4;
    bPoint = 0x08;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p4 > aScore)
    {
    aScore = p4;
    aPoint = 0x08;
    aIsBiggerSide = false;
    }

    if (aIsBiggerSide == bIsBiggerSide)
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[4][((aPoint | bPoint) & 0x0F) | ((aPoint & bPoint) << 4)];
    }
    else
    {
    c = contributions4D[5][aPoint | bPoint];
    }
    }
    else
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[6][(aPoint & 0x0F) | (bPoint << 4)];
    }
    else
    {
    c = contributions4D[6][(bPoint & 0x0F) | (aPoint << 4)];
    }
    }
    }
    else
    {
    var aIsBiggerSide = true;
    var bIsBiggerSide = true;

    if (xins + yins < zins + wins)
    {
    aScore = xins + yins;
    aPoint = 0x0C;
    }
    else
    {
    aScore = zins + wins;
    aPoint = 0x03;
    }

    if (xins + zins < yins + wins)
    {
    bScore = xins + zins;
    bPoint = 0x0A;
    }
    else
    {
    bScore = yins + wins;
    bPoint = 0x05;
    }

    if (xins + wins < yins + zins)
    {
    var score = xins + wins;
    if (aScore <= bScore && score < bScore)
    {
    bScore = score;
    bPoint = 0x06;
    }
    else if (aScore > bScore && score < aScore)
    {
    aScore = score;
    aPoint = 0x06;
    }
    }
    else
    {
    var score = yins + zins;
    if (aScore <= bScore && score < bScore)
    {
    bScore = score;
    bPoint = 0x09;
    }
    else if (aScore > bScore && score < aScore)
    {
    aScore = score;
    aPoint = 0x09;
    }
    }

    var p1 = 3 - inSum + xins;
    if (aScore <= bScore && p1 < bScore)
    {
    bScore = p1;
    bPoint = 0x0E;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p1 < aScore)
    {
    aScore = p1;
    aPoint = 0x0E;
    aIsBiggerSide = false;
    }

    var p2 = 3 - inSum + yins;
    if (aScore <= bScore && p2 < bScore)
    {
    bScore = p2;
    bPoint = 0x0D;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p2 < aScore)
    {
    aScore = p2;
    aPoint = 0x0D;
    aIsBiggerSide = false;
    }

    var p3 = 3 - inSum + zins;
    if (aScore <= bScore && p3 < bScore)
    {
    bScore = p3;
    bPoint = 0x0B;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p3 < aScore)
    {
    aScore = p3;
    aPoint = 0x0B;
    aIsBiggerSide = false;
    }

    var p4 = 3 - inSum + wins;
    if (aScore <= bScore && p4 < bScore)
    {
    bScore = p4;
    bPoint = 0x07;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p4 < aScore)
    {
    aScore = p4;
    aPoint = 0x07;
    aIsBiggerSide = false;
    }

    if (aIsBiggerSide == bIsBiggerSide)
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[7][((aPoint & bPoint) & 0x0F) | ((aPoint | bPoint) << 4)];
    }
    else
    {
    c = contributions4D[8][aPoint & bPoint];
    }
    }
    else
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[9][(aPoint & 0x0F) | (bPoint << 4)];
    }
    else
    {
    c = contributions4D[9][(bPoint & 0x0F) | (aPoint << 4)];
    }
    }
    }
    var hash =
    (int)(zins - wins + 1) |
    (int)(yins - zins + 1) << 1 |
    (int)(yins - wins + 1) << 2 |
    (int)(xins - yins + 1) << 3 |
    (int)(xins - zins + 1) << 4 |
    (int)(xins - wins + 1) << 5 |
    (int)inSum << 6 |
    (int)(inSum + wins) << 8 |
    (int)(inSum + zins) << 11 |
    (int)(inSum + yins) << 14 |
    (int)(inSum + xins) << 17;

    var c = lookup4D[hash];

    var value = 0.0;
    while (c != null)
    @@ -927,7 +397,6 @@ public double Evaluate(double x, double y, double z, double w)

    c = c.Next;
    }

    return value * NORM_4D;
    }

  2. @digitalshadow digitalshadow revised this gist Jan 23, 2015. 1 changed file with 700 additions and 112 deletions.
    812 changes: 700 additions & 112 deletions OpenSimplexNoise.cs
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    /* OpenSimplex Noise in C#
    * Ported from https://gist.github.com/KdotJPG/b1270127455a94ac5d19
    * and heavily refactored to improve performance and readability of the code.
    * The main difference is the removal of the "extra" points which means it won't
    * have exactly the same output as the original code. In terms of visual quality,
    * I've noticed no difference, but in terms of performance it's nearly twice as
    * fast in 3rd and 4th dimensions. */
    * and heavily refactored to improve performance. The main difference is that once the
    * bit flags are determined, the result is pulled from a lookup table, saving the time
    * used deciphering the bit flags again. */

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;

    namespace NoiseTest
    {
    @@ -18,17 +19,15 @@ public class OpenSimplexNoise
    private const double SQUISH_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2;
    private const double SQUISH_3D = 1.0 / 3.0; //(Math.sqrt(3+1)-1)/3;
    private const double SQUISH_4D = 0.309016994374947; //(Math.sqrt(4+1)-1)/4;
    private const double NORM_2D = 47;
    private const double NORM_3D = 103;
    private const double NORM_4D = 30;
    private const double NORM_2D = 1.0 / 47.0;
    private const double NORM_3D = 1.0 / 103.0;
    private const double NORM_4D = 1.0 / 30.0;

    private byte[] perm;
    private byte[] perm2D;
    private byte[] perm3D;
    private byte[] perm4D;

    //Gradients for 2D. They approximate the directions to the
    //vertices of an octagon from the center.
    private static double[] gradients2D = new double[]
    {
    5, 2, 2, 5,
    @@ -37,11 +36,7 @@ public class OpenSimplexNoise
    -5, -2, -2, -5,
    };

    //Gradients for 3D. They approximate the directions to the
    //vertices of a rhombicuboctahedron from the center, skewed so
    //that the triangular and square facets can be inscribed inside
    //circles of the same radius.
    private static double[] gradients3D = new double[]
    private static double[] gradients3D =
    {
    -11, 4, 4, -4, 11, 4, -4, 4, 11,
    11, 4, 4, 4, 11, 4, 4, 4, 11,
    @@ -53,11 +48,7 @@ public class OpenSimplexNoise
    11, -4, -4, 4, -11, -4, 4, -4, -11,
    };

    //Gradients for 4D. They approximate the directions to the
    //vertices of a disprismatotesseractihexadecachoron from the center,
    //skewed so that the tetrahedral and cubic facets can be inscribed inside
    //spheres of the same radius.
    private static double[] gradients4D = new double[]
    private static double[] gradients4D =
    {
    3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
    -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
    @@ -77,35 +68,161 @@ public class OpenSimplexNoise
    -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
    };

    private static readonly Contribution2[][] contributions2D =
    {
    new Contribution2[] { new Contribution2(1, 1, 0), new Contribution2(1, 0, 1), new Contribution2(2, 1, 1) },
    new Contribution2[] { new Contribution2(1, 1, 0), new Contribution2(1, 0, 1), new Contribution2(0, 0, 0) }
    };
    private static Contribution2[][] contributions2D;
    private static Contribution3[][] contributions3D;
    private static Contribution4[][] contributions4D;

    private static readonly Contribution3[][] contributions3D =
    static OpenSimplexNoise()
    {
    new Contribution3[] { new Contribution3(0, 0, 0, 0), new Contribution3(1, 1, 0, 0), new Contribution3(1, 0, 1, 0), new Contribution3(1, 0, 0, 1) },
    new Contribution3[] { new Contribution3(2, 1, 1, 0), new Contribution3(2, 1, 0, 1), new Contribution3(2, 0, 1, 1), new Contribution3(3, 1, 1, 1) },
    new Contribution3[] { new Contribution3(1, 1, 0, 0), new Contribution3(1, 0, 1, 0), new Contribution3(1, 0, 0, 1), new Contribution3(2, 1, 1, 0), new Contribution3(2, 1, 0, 1), new Contribution3(2, 0, 1, 1)}
    };
    var base2D = new int[][]
    {
    new int[] { 1, 1, 0, 1, 0, 1, 0, 0, 0 },
    new int[] { 1, 1, 0, 1, 0, 1, 2, 1, 1 }
    };
    var permutations2D = new int[][]
    {
    new int[] { 0, 0, 1, -1, 0, -1, 1, 2, 1, 1 },
    new int[] { 1, 2, 2, 0, 2, 0, 2, 0, 0, 0 }
    };

    contributions2D = new Contribution2[base2D.Length][];
    for (int i = 0; i < base2D.Length; i++)
    {
    var permutations = permutations2D[i];
    var set = base2D[permutations[0]];
    var contributions = new Contribution2[permutations.Length / 3];

    for (int j = 1; j < permutations.Length; j += 3)
    {
    Contribution2 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 3)
    {
    current = new Contribution2(set[k], set[k + 1], set[k + 2]);
    if (previous == null)
    {
    contributions[j / 3] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    }
    current.Next = new Contribution2(permutations[j], permutations[j + 1], permutations[j + 2]);
    }
    contributions2D[i] = contributions;
    }

    var 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 }
    };
    var permutations3D = new int[][]
    {
    new int[] { 0 ,0, -1, 0, 0, 0, 0, -1, -1, 0, 1, -1, 0, 0, 1, 0, -1, 0, -1, 1, 0, 0, 0, 1, -1, 0, 1, 1, 0, 0, 1, 1, -1, 0, -1, 0, 1, 0, 0, -1, 1, 0, 1, -1, 1, 0, 1, 0, 1, 0, -1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
    new int[] { 0 ,2, 0, 0, 0, 1, -1, -1, -1, 2, 1, 0, 0, 1, 1, -1, -1, 2, 0, 1, 0, 1, -1, 1, -1, 2, 1, 1, 0, 1, 1, 1, -1, 2, 0, 0, 1, 1, -1, -1, 1, 2, 1, 0, 1, 1, 1, -1, 1, 2, 0, 1, 1, 1, -1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1 },
    new int[] { 1 ,3, 0, 0, 0, 3, 0, 0, 0, 3, 2, 0, 0, 3, 1, 0, 0, 3, 0, 2, 0, 3, 0, 1, 0, 3, 2, 1, 0, 3, 1, 2, 0, 3, 0, 0, 1, 3, 0, 0, 2, 3, 2, 0, 1, 3, 1, 0, 2, 3, 0, 2, 1, 3, 0, 1, 2, 3, 2, 1, 1, 3, 1, 2, 2 },
    new int[] { 1 ,1, 0, 0, 0, 2, 0, 0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 1, 0, 1, 0, 2, 0, 2, 0, 1, 1, 1, 0, 2, 2, 2, 0, 1, 0, 0, 1, 2, 0, 0, 2, 1, 1, 0, 1, 2, 2, 0, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2 },
    new int[] { 2 ,0, 0, 0, 0, 1, -1, 1, 1, 0, 0, 0, 0, 1, 1, -1, 1, 0, 0, 0, 0, 1, -1, 1, 1, 0, 0, 0, 0, 1, 1, 1, -1, 3, 1, 1, 1, 2, 0, 0, 2, 3, 1, 1, 1, 2, 2, 0, 0, 3, 1, 1, 1, 2, 0, 2, 0, 3, 1, 1, 1, 2, 2, 0, 0 },
    new int[] { 2 ,1, -1, 1, 1, 2, 0, 0, 2, 1, -1, 1, 1, 2, 2, 0, 0, 1, -1, 1, 1, 2, 0, 2, 0, 1, -1, 1, 1, 2, 2, 0, 0, 1, 1, -1, 1, 2, 0, 0, 2, 1, 1, -1, 1, 2, 2, 0, 0, 1, 1, -1, 1, 2, 0, 2, 0, 1, 1, -1, 1, 2, 2, 0, 0, 1, -1, 1, 1, 2, 0, 0, 2, 1, -1, 1, 1, 2, 2, 0, 0, 1, -1, 1, 1, 2, 0, 2, 0, 1, -1, 1, 1, 2, 2, 0, 0, 1, 1, 1, -1, 2, 0, 0, 2, 1, 1, 1, -1, 2, 2, 0, 0, 1, 1, 1, -1, 2, 0, 2, 0, 1, 1, 1, -1, 2, 2, 0, 0 }
    };

    contributions3D = new Contribution3[permutations3D.Length][];
    for (int i = 0; i < permutations3D.Length; i++)
    {
    var permutations = permutations3D[i];
    var set = base3D[permutations[0]];
    var contributions = new Contribution3[permutations.Length / 8];

    private static readonly Contribution4[][] contributions4D =
    for (int j = 1; j < permutations.Length; j += 8)
    {
    Contribution3 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 4)
    {
    current = new Contribution3(set[k], set[k + 1], set[k + 2], set[k + 3]);
    if (previous == null)
    {
    contributions[j / 8] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    }
    current.Next = new Contribution3(permutations[j], permutations[j + 1], permutations[j + 2], permutations[j + 3]);
    current.Next.Next = new Contribution3(permutations[j + 4], permutations[j + 5], permutations[j + 6], permutations[j + 7]);
    }
    contributions3D[i] = contributions;
    }

    var base4D = new int[][]
    {
    new int[] { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 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 2, 2, 2, -1, 1, 1, 1, 3, 2, 1, 1, 1, 3, 1, 2, 2, 2, 2, -1, 1, 1, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 1, 1, 1, -1, 3, 2, 0, 0, 0, 3, 1, 0, 0, 0, 2, 1, 1, 1, -1, 3, 0, 2, 0, 0, 3, 0, 1, 0, 0, 2, 1, 1, 1, -1, 3, 2, 1, 0, 0, 3, 1, 2, 0, 0, 2, 1, 1, 1, -1, 3, 0, 0, 2, 0, 3, 0, 0, 1, 0, 2, 1, 1, 1, -1, 3, 2, 0, 1, 0, 3, 1, 0, 2, 0, 2, 1, 1, 1, -1, 3, 0, 2, 1, 0, 3, 0, 1, 2, 0, 2, 1, 1, 1, -1, 3, 2, 1, 1, 0, 3, 1, 2, 2, 0, 2, 1, 1, 1, -1, 3, 0, 0, 0, 1, 3, 0, 0, 0, 2, 2, 1, 1, 1, -1, 3, 2, 0, 0, 1, 3, 1, 0, 0, 2, 2, 1, 1, 1, -1, 3, 0, 2, 0, 1, 3, 0, 1, 0, 2, 2, 1, 1, 1, -1, 3, 2, 1, 0, 1, 3, 1, 2, 0, 2, 2, 1, 1, 1, -1, 3, 0, 0, 2, 1, 3, 0, 0, 1, 2, 2, 1, 1, 1, -1, 3, 2, 0, 1, 1, 3, 1, 0, 2, 2, 2, 1, 1, 1, -1, 3, 0, 2, 1, 1, 3, 0, 1, 2, 2, 2, 1, 1, 1, -1, 3, 2, 1, 1, 1, 3, 1, 2, 2, 2, 2, 1, 1, 1, -1 }
    };

    contributions4D = new Contribution4[permutations4D.Length][];
    for (int i = 0; i < permutations4D.Length; i++)
    {
    var permutations = permutations4D[i];
    var set = base4D[permutations[0]];
    var contributions = new Contribution4[permutations.Length / 15];

    for (int j = 1; j < permutations.Length; j += 15)
    {
    Contribution4 previous = null, current = null;
    for (int k = 0; k < set.Length; k += 5)
    {
    current = new Contribution4(set[k], set[k + 1], set[k + 2], set[k + 3], set[k + 4]);
    if (previous == null)
    {
    contributions[j / 15] = current;
    }
    else
    {
    previous.Next = current;
    }
    previous = current;
    }
    current.Next = new Contribution4(permutations[j], permutations[j + 1], permutations[j + 2], permutations[j + 3], permutations[j + 4]);
    current.Next.Next = new Contribution4(permutations[j + 5], permutations[j + 6], permutations[j + 7], permutations[j + 8], permutations[j + 9]);
    current.Next.Next.Next = new Contribution4(permutations[j + 10], permutations[j + 11], permutations[j + 12], permutations[j + 13], permutations[j + 14]);
    }
    contributions4D[i] = contributions;
    }
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static int FastFloor(double x)
    {
    new Contribution4[] { new Contribution4(0, 0, 0, 0, 0), new Contribution4(1, 1, 0, 0, 0), new Contribution4(1, 0, 1, 0, 0), new Contribution4(1, 0, 0, 1, 0), new Contribution4(1, 0, 0, 0, 1) },
    new Contribution4[] { new Contribution4(3, 1, 1, 1, 0), new Contribution4(3, 1, 1, 0, 1), new Contribution4(3, 1, 0, 1, 1), new Contribution4(3, 0, 1, 1, 1), new Contribution4(4, 1, 1, 1, 1) },
    new Contribution4[] { new Contribution4(1, 1, 0, 0, 0), new Contribution4(1, 0, 1, 0, 0), new Contribution4(1, 0, 0, 1, 0), new Contribution4(1, 0, 0, 0, 1), new Contribution4(2, 1, 1, 0, 0), new Contribution4(2, 1, 0, 1, 0), new Contribution4(2, 1, 0, 0, 1), new Contribution4(2, 0, 1, 1, 0), new Contribution4(2, 0, 1, 0, 1), new Contribution4(2, 0, 0, 1, 1) },
    new Contribution4[] { new Contribution4(3, 1, 1, 1, 0), new Contribution4(3, 1, 1, 0, 1), new Contribution4(3, 1, 0, 1, 1), new Contribution4(3, 0, 1, 1, 1), new Contribution4(2, 1, 1, 0, 0), new Contribution4(2, 1, 0, 1, 0), new Contribution4(2, 1, 0, 0, 1), new Contribution4(2, 0, 1, 1, 0), new Contribution4(2, 0, 1, 0, 1), new Contribution4(2, 0, 0, 1, 1) }
    };
    var xi = (int)x;
    return x < xi ? xi - 1 : xi;
    }

    public OpenSimplexNoise()
    : this(DateTime.Now.Ticks)
    {
    }

    //Initializes the class using a permutation array generated from a 64-bit seed.
    //Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array)
    //Uses a simple 64-bit LCG.
    public OpenSimplexNoise(long seed)
    {
    perm = new byte[256];
    @@ -129,52 +246,76 @@ public OpenSimplexNoise(long seed)
    r += (i + 1);
    }
    perm[i] = source[r];
    perm2D[i] = (byte)((perm[i] % 8) * 2);
    perm3D[i] = (byte)((perm[i] % 12) * 3);
    perm4D[i] = (byte)((perm[i] % 64) * 4);
    perm2D[i] = (byte)(perm[i] & 0x0E);
    perm3D[i] = (byte)((perm[i] % 24) * 3);
    perm4D[i] = (byte)(perm[i] & 0xFC);
    source[r] = source[i];
    }
    }

    public double Evaluate(double x, double y)
    {
    //Place input coordinates onto grid.
    var stretchOffset = (x + y) * STRETCH_2D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;

    //Floor to get grid coordinates of rhombus (stretched square) super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;
    var xsb = FastFloor(xs);
    var ysb = FastFloor(ys);

    //Skew out to get actual coordinates of rhombus origin. We'll need these later.
    var squishOffset = (xsb + ysb) * SQUISH_2D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;

    //Compute grid coordinates relative to rhombus origin.
    var xins = xs - xsb;
    var yins = ys - ysb;

    //Sum those together to get a value that determines which region we're in.
    var inSum = xins + yins;
    Contribution2 c;

    Contribution2[] contributions;
    if (inSum > 1) //We're inside the triangle (2-Simplex) at (0,0)
    {
    contributions = contributions2D[0];
    var inSum = xins + yins;
    if (inSum <= 1)
    {
    var zins = 1 - inSum;
    if (zins > xins || zins > yins)
    {
    if (xins > yins)
    {
    c = contributions2D[0][0];
    }
    else
    {
    c = contributions2D[0][1];
    }
    }
    else
    {
    c = contributions2D[0][2];
    }
    }
    else //We're inside the triangle (2-Simplex) at (1,1)
    else
    {
    contributions = contributions2D[1];
    var zins = 2 - inSum;
    if (zins < xins || zins < yins)
    {
    if (xins > yins)
    {
    c = contributions2D[1][0];
    }
    else
    {
    c = contributions2D[1][1];
    }
    }
    else
    {
    c = contributions2D[1][2];
    }
    }

    double value = 0;
    foreach (var c in contributions)
    var value = 0.0;
    while (c != null)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    @@ -190,59 +331,176 @@ public double Evaluate(double x, double y)
    attn *= attn;
    value += attn * attn * valuePart;
    }
    c = c.Next;
    }

    return value / NORM_2D;
    return value * NORM_2D;
    }


    public double Evaluate(double x, double y, double z)
    {
    //Place input coordinates on simplectic honeycomb.
    var stretchOffset = (x + y + z) * STRETCH_3D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;
    var zs = z + stretchOffset;

    //Floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;
    var zsb = zs > 0 ? (int)zs : (int)zs - 1;
    var xsb = FastFloor(xs);
    var ysb = FastFloor(ys);
    var zsb = FastFloor(zs);

    //Skew out to get actual coordinates of rhombohedron origin. We'll need these later.
    var squishOffset = (xsb + ysb + zsb) * SQUISH_3D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;

    //Compute simplectic honeycomb coordinates relative to rhombohedral origin.
    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;

    //Sum those together to get a value that determines which region we're in.
    Contribution3 c;
    var inSum = xins + yins + zins;

    Contribution3[] contributions;
    if (inSum <= 1) //We're inside the tetrahedron (3-Simplex) at (0,0,0)
    if (inSum <= 1)
    {
    contributions = contributions3D[0];
    var aPoint = 0x01;
    var aScore = xins;
    var bPoint = 0x02;
    var bScore = yins;
    if (aScore >= bScore && zins > bScore)
    {
    bScore = zins;
    bPoint = 0x04;
    }
    else if (aScore < bScore && zins > aScore)
    {
    aScore = zins;
    aPoint = 0x04;
    }

    var wins = 1 - inSum;
    if (wins > aScore || wins > bScore)
    {
    c = contributions3D[0][bScore > aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions3D[1][aPoint | bPoint];
    }
    }
    else if (inSum >= 2) //We're inside the tetrahedron (3-Simplex) at (1,1,1)
    else if (inSum >= 2)
    {
    contributions = contributions3D[1];
    var aPoint = 0x06;
    var aScore = xins;
    var bPoint = 0x05;
    var bScore = yins;
    if (aScore <= bScore && zins < bScore)
    {
    bScore = zins;
    bPoint = 0x03;
    }
    else if (aScore > bScore && zins < aScore)
    {
    aScore = zins;
    aPoint = 0x03;
    }

    var wins = 3 - inSum;
    if (wins < aScore || wins < bScore)
    {
    c = contributions3D[2][bScore < aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions3D[3][aPoint & bPoint];
    }
    }
    else //We're inside the octahedron (Rectified 3-Simplex) in between.
    {
    contributions = contributions3D[2];
    else
    {
    byte aPoint;
    bool aIsFurtherSide;
    byte bPoint;
    bool bIsFurtherSide;

    var p1 = xins + yins;
    if (p1 > 1)
    {
    p1 = p1 - 1;
    aPoint = 0x03;
    aIsFurtherSide = true;
    }
    else
    {
    p1 = 1 - p1;
    aPoint = 0x04;
    aIsFurtherSide = false;
    }

    var p2 = xins + zins;
    if (p2 > 1)
    {
    p2 = p2 - 1;
    bPoint = 0x05;
    bIsFurtherSide = true;
    }
    else
    {
    p2 = 1 - p2;
    bPoint = 0x02;
    bIsFurtherSide = false;
    }

    var p3 = yins + zins;
    if (p3 > 1)
    {
    p3 = p3 - 1;
    if (p1 <= p2 && p1 < p3)
    {
    aPoint = 0x06;
    aIsFurtherSide = true;
    }
    else if (p1 > p2 && p2 < p3)
    {
    bPoint = 0x06;
    bIsFurtherSide = true;
    }
    }
    else
    {
    p3 = 1 - p3;
    if (p1 <= p2 && p1 < p3)
    {
    aPoint = 0x01;
    aIsFurtherSide = false;
    }
    else if (p1 > p2 && p2 < p3)
    {
    bPoint = 0x01;
    bIsFurtherSide = false;
    }
    }

    if (aIsFurtherSide == bIsFurtherSide)
    {
    c = contributions3D[4][aIsFurtherSide ? ((aPoint & bPoint) & 0x03) | 0x4 : (aPoint | bPoint) & 0x03];
    }
    else
    {
    if (aIsFurtherSide)
    {
    c = contributions3D[5][((aPoint & 0x03) << 2) | (bPoint & 0x03)];
    }
    else
    {
    c = contributions3D[5][((bPoint & 0x03) << 2) | (aPoint & 0x03)];
    }
    }
    }

    double value = 0;
    foreach (var c in contributions)
    var value = 0.0;
    while (c != null)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    @@ -260,68 +518,393 @@ public double Evaluate(double x, double y, double z)
    attn *= attn;
    value += attn * attn * valuePart;
    }
    }

    return value / NORM_3D;
    c = c.Next;
    }
    return value * NORM_3D;
    }

    public double Evaluate(double x, double y, double z, double w)
    {
    //Place input coordinates on simplectic honeycomb.
    var stretchOffset = (x + y + z + w) * STRETCH_4D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;
    var zs = z + stretchOffset;
    var ws = w + stretchOffset;

    //Floor to get simplectic honeycomb coordinates of rhombo-hypercube super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;
    var zsb = zs > 0 ? (int)zs : (int)zs - 1;
    var wsb = ws > 0 ? (int)ws : (int)ws - 1;
    var xsb = FastFloor(xs);
    var ysb = FastFloor(ys);
    var zsb = FastFloor(zs);
    var wsb = FastFloor(ws);

    //Skew out to get actual coordinates of stretched rhombo-hypercube origin. We'll need these later.
    var squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;
    var wb = wsb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;
    var dw0 = w - wb;

    //Compute simplectic honeycomb coordinates relative to rhombo-hypercube origin.
    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;
    var wins = ws - wsb;

    //Sum those together to get a value that determines which region we're in.
    var inSum = xins + yins + zins + wins;
    double aScore, bScore;
    int aPoint, bPoint;

    Contribution4 c;

    Contribution4[] contributions;
    if (inSum <= 1) // We're inside the pentachoron (4-Simplex) at (0,0,0,0)
    var inSum = xins + yins + zins + wins;
    if (inSum <= 1)
    {
    contributions = contributions4D[0];
    aPoint = 0x01;
    aScore = xins;
    bPoint = 0x02;
    bScore = yins;
    if (aScore >= bScore && zins > bScore)
    {
    bScore = zins;
    bPoint = 0x04;
    }
    else if (aScore < bScore && zins > aScore)
    {
    aScore = zins;
    aPoint = 0x04;
    }
    if (aScore >= bScore && wins > bScore)
    {
    bScore = wins;
    bPoint = 0x08;
    }
    else if (aScore < bScore && wins > aScore)
    {
    aScore = wins;
    aPoint = 0x08;
    }
    var uins = 1 - inSum;
    if (uins > aScore || uins > bScore)
    {
    c = contributions4D[0][bScore > aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions4D[1][aPoint | bPoint];
    }
    }
    else if (inSum >= 3) //We're inside the pentachoron (4-Simplex) at (1,1,1,1)
    else if (inSum >= 3)
    {
    contributions = contributions4D[1];
    aPoint = 0x0E;
    aScore = xins;
    bPoint = 0x0D;
    bScore = yins;
    if (aScore <= bScore && zins < bScore)
    {
    bScore = zins;
    bPoint = 0x0B;
    }
    else if (aScore > bScore && zins < aScore)
    {
    aScore = zins;
    aPoint = 0x0B;
    }
    if (aScore <= bScore && wins < bScore)
    {
    bScore = wins;
    bPoint = 0x07;
    }
    else if (aScore > bScore && wins < aScore)
    {
    aScore = wins;
    aPoint = 0x07;
    }

    var uins = 4 - inSum;
    if (uins < aScore || uins < bScore)
    {
    c = contributions4D[2][bScore < aScore ? bPoint : aPoint];
    }
    else
    {
    c = contributions4D[3][aPoint & bPoint];
    }
    }
    else if (inSum <= 2) // We're inside the first dispentachoron (Rectified 4-Simplex)
    else if (inSum <= 2)
    {
    contributions = contributions4D[2];
    var aIsBiggerSide = true;
    var bIsBiggerSide = true;

    if (xins + yins > zins + wins)
    {
    aScore = xins + yins;
    aPoint = 0x03;
    }
    else
    {
    aScore = zins + wins;
    aPoint = 0x0C;
    }

    if (xins + zins > yins + wins)
    {
    bScore = xins + zins;
    bPoint = 0x05;
    }
    else
    {
    bScore = yins + wins;
    bPoint = 0x0A;
    }

    if (xins + wins > yins + zins)
    {
    var score = xins + wins;
    if (aScore >= bScore && score > bScore)
    {
    bScore = score;
    bPoint = 0x09;
    }
    else if (aScore < bScore && score > aScore)
    {
    aScore = score;
    aPoint = 0x09;
    }
    }
    else
    {
    var score = yins + zins;
    if (aScore >= bScore && score > bScore)
    {
    bScore = score;
    bPoint = 0x06;
    }
    else if (aScore < bScore && score > aScore)
    {
    aScore = score;
    aPoint = 0x06;
    }
    }

    var p1 = 2 - inSum + xins;
    if (aScore >= bScore && p1 > bScore)
    {
    bScore = p1;
    bPoint = 0x01;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p1 > aScore)
    {
    aScore = p1;
    aPoint = 0x01;
    aIsBiggerSide = false;
    }

    var p2 = 2 - inSum + yins;
    if (aScore >= bScore && p2 > bScore)
    {
    bScore = p2;
    bPoint = 0x02;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p2 > aScore)
    {
    aScore = p2;
    aPoint = 0x02;
    aIsBiggerSide = false;
    }

    var p3 = 2 - inSum + zins;
    if (aScore >= bScore && p3 > bScore)
    {
    bScore = p3;
    bPoint = 0x04;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p3 > aScore)
    {
    aScore = p3;
    aPoint = 0x04;
    aIsBiggerSide = false;
    }

    var p4 = 2 - inSum + wins;
    if (aScore >= bScore && p4 > bScore)
    {
    bScore = p4;
    bPoint = 0x08;
    bIsBiggerSide = false;
    }
    else if (aScore < bScore && p4 > aScore)
    {
    aScore = p4;
    aPoint = 0x08;
    aIsBiggerSide = false;
    }

    if (aIsBiggerSide == bIsBiggerSide)
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[4][((aPoint | bPoint) & 0x0F) | ((aPoint & bPoint) << 4)];
    }
    else
    {
    c = contributions4D[5][aPoint | bPoint];
    }
    }
    else
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[6][(aPoint & 0x0F) | (bPoint << 4)];
    }
    else
    {
    c = contributions4D[6][(bPoint & 0x0F) | (aPoint << 4)];
    }
    }
    }
    else // We're inside the second dispentachoron (Rectified 4-Simplex)
    else
    {
    contributions = contributions4D[3];
    var aIsBiggerSide = true;
    var bIsBiggerSide = true;

    if (xins + yins < zins + wins)
    {
    aScore = xins + yins;
    aPoint = 0x0C;
    }
    else
    {
    aScore = zins + wins;
    aPoint = 0x03;
    }

    if (xins + zins < yins + wins)
    {
    bScore = xins + zins;
    bPoint = 0x0A;
    }
    else
    {
    bScore = yins + wins;
    bPoint = 0x05;
    }

    if (xins + wins < yins + zins)
    {
    var score = xins + wins;
    if (aScore <= bScore && score < bScore)
    {
    bScore = score;
    bPoint = 0x06;
    }
    else if (aScore > bScore && score < aScore)
    {
    aScore = score;
    aPoint = 0x06;
    }
    }
    else
    {
    var score = yins + zins;
    if (aScore <= bScore && score < bScore)
    {
    bScore = score;
    bPoint = 0x09;
    }
    else if (aScore > bScore && score < aScore)
    {
    aScore = score;
    aPoint = 0x09;
    }
    }

    var p1 = 3 - inSum + xins;
    if (aScore <= bScore && p1 < bScore)
    {
    bScore = p1;
    bPoint = 0x0E;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p1 < aScore)
    {
    aScore = p1;
    aPoint = 0x0E;
    aIsBiggerSide = false;
    }

    var p2 = 3 - inSum + yins;
    if (aScore <= bScore && p2 < bScore)
    {
    bScore = p2;
    bPoint = 0x0D;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p2 < aScore)
    {
    aScore = p2;
    aPoint = 0x0D;
    aIsBiggerSide = false;
    }

    var p3 = 3 - inSum + zins;
    if (aScore <= bScore && p3 < bScore)
    {
    bScore = p3;
    bPoint = 0x0B;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p3 < aScore)
    {
    aScore = p3;
    aPoint = 0x0B;
    aIsBiggerSide = false;
    }

    var p4 = 3 - inSum + wins;
    if (aScore <= bScore && p4 < bScore)
    {
    bScore = p4;
    bPoint = 0x07;
    bIsBiggerSide = false;
    }
    else if (aScore > bScore && p4 < aScore)
    {
    aScore = p4;
    aPoint = 0x07;
    aIsBiggerSide = false;
    }

    if (aIsBiggerSide == bIsBiggerSide)
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[7][((aPoint & bPoint) & 0x0F) | ((aPoint | bPoint) << 4)];
    }
    else
    {
    c = contributions4D[8][aPoint & bPoint];
    }
    }
    else
    {
    if (aIsBiggerSide)
    {
    c = contributions4D[9][(aPoint & 0x0F) | (bPoint << 4)];
    }
    else
    {
    c = contributions4D[9][(bPoint & 0x0F) | (aPoint << 4)];
    }
    }
    }

    double value = 0;
    foreach (var c in contributions)
    var value = 0.0;
    while (c != null)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    @@ -341,15 +924,18 @@ public double Evaluate(double x, double y, double z, double w)
    attn *= attn;
    value += attn * attn * valuePart;
    }

    c = c.Next;
    }

    return value / NORM_4D;
    return value * NORM_4D;
    }

    private class Contribution2
    {
    public readonly double dx, dy;
    public readonly int xsb, ysb;
    public double dx, dy;
    public int xsb, ysb;
    public Contribution2 Next;

    public Contribution2(double multiplier, int xsb, int ysb)
    {
    @@ -362,8 +948,9 @@ public Contribution2(double multiplier, int xsb, int ysb)

    private class Contribution3
    {
    public readonly double dx, dy, dz;
    public readonly int xsb, ysb, zsb;
    public double dx, dy, dz;
    public int xsb, ysb, zsb;
    public Contribution3 Next;

    public Contribution3(double multiplier, int xsb, int ysb, int zsb)
    {
    @@ -378,8 +965,9 @@ public Contribution3(double multiplier, int xsb, int ysb, int zsb)

    private class Contribution4
    {
    public readonly double dx, dy, dz, dw;
    public readonly int xsb, ysb, zsb, wsb;
    public double dx, dy, dz, dw;
    public int xsb, ysb, zsb, wsb;
    public Contribution4 Next;

    public Contribution4(double multiplier, int xsb, int ysb, int zsb, int wsb)
    {
  3. @digitalshadow digitalshadow revised this gist Jan 15, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions OpenSimplexNoise.cs
    Original file line number Diff line number Diff line change
    @@ -346,7 +346,7 @@ public double Evaluate(double x, double y, double z, double w)
    return value / NORM_4D;
    }

    private struct Contribution2
    private class Contribution2
    {
    public readonly double dx, dy;
    public readonly int xsb, ysb;
    @@ -360,7 +360,7 @@ public Contribution2(double multiplier, int xsb, int ysb)
    }
    }

    private struct Contribution3
    private class Contribution3
    {
    public readonly double dx, dy, dz;
    public readonly int xsb, ysb, zsb;
    @@ -376,7 +376,7 @@ public Contribution3(double multiplier, int xsb, int ysb, int zsb)
    }
    }

    private struct Contribution4
    private class Contribution4
    {
    public readonly double dx, dy, dz, dw;
    public readonly int xsb, ysb, zsb, wsb;
  4. @digitalshadow digitalshadow created this gist Jan 15, 2015.
    397 changes: 397 additions & 0 deletions OpenSimplexNoise.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,397 @@
    /* OpenSimplex Noise in C#
    * Ported from https://gist.github.com/KdotJPG/b1270127455a94ac5d19
    * and heavily refactored to improve performance and readability of the code.
    * The main difference is the removal of the "extra" points which means it won't
    * have exactly the same output as the original code. In terms of visual quality,
    * I've noticed no difference, but in terms of performance it's nearly twice as
    * fast in 3rd and 4th dimensions. */

    using System;

    namespace NoiseTest
    {
    public class OpenSimplexNoise
    {
    private const double STRETCH_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2;
    private const double STRETCH_3D = -1.0 / 6.0; //(1/Math.sqrt(3+1)-1)/3;
    private const double STRETCH_4D = -0.138196601125011; //(1/Math.sqrt(4+1)-1)/4;
    private const double SQUISH_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2;
    private const double SQUISH_3D = 1.0 / 3.0; //(Math.sqrt(3+1)-1)/3;
    private const double SQUISH_4D = 0.309016994374947; //(Math.sqrt(4+1)-1)/4;
    private const double NORM_2D = 47;
    private const double NORM_3D = 103;
    private const double NORM_4D = 30;

    private byte[] perm;
    private byte[] perm2D;
    private byte[] perm3D;
    private byte[] perm4D;

    //Gradients for 2D. They approximate the directions to the
    //vertices of an octagon from the center.
    private static double[] gradients2D = new double[]
    {
    5, 2, 2, 5,
    -5, 2, -2, 5,
    5, -2, 2, -5,
    -5, -2, -2, -5,
    };

    //Gradients for 3D. They approximate the directions to the
    //vertices of a rhombicuboctahedron from the center, skewed so
    //that the triangular and square facets can be inscribed inside
    //circles of the same radius.
    private static double[] gradients3D = new double[]
    {
    -11, 4, 4, -4, 11, 4, -4, 4, 11,
    11, 4, 4, 4, 11, 4, 4, 4, 11,
    -11, -4, 4, -4, -11, 4, -4, -4, 11,
    11, -4, 4, 4, -11, 4, 4, -4, 11,
    -11, 4, -4, -4, 11, -4, -4, 4, -11,
    11, 4, -4, 4, 11, -4, 4, 4, -11,
    -11, -4, -4, -4, -11, -4, -4, -4, -11,
    11, -4, -4, 4, -11, -4, 4, -4, -11,
    };

    //Gradients for 4D. They approximate the directions to the
    //vertices of a disprismatotesseractihexadecachoron from the center,
    //skewed so that the tetrahedral and cubic facets can be inscribed inside
    //spheres of the same radius.
    private static double[] gradients4D = new double[]
    {
    3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
    -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
    3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3,
    -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3,
    3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3,
    -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3,
    3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3,
    -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3,
    3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3,
    -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3,
    3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3,
    -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3,
    3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3,
    -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3,
    3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3,
    -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
    };

    private static readonly Contribution2[][] contributions2D =
    {
    new Contribution2[] { new Contribution2(1, 1, 0), new Contribution2(1, 0, 1), new Contribution2(2, 1, 1) },
    new Contribution2[] { new Contribution2(1, 1, 0), new Contribution2(1, 0, 1), new Contribution2(0, 0, 0) }
    };

    private static readonly Contribution3[][] contributions3D =
    {
    new Contribution3[] { new Contribution3(0, 0, 0, 0), new Contribution3(1, 1, 0, 0), new Contribution3(1, 0, 1, 0), new Contribution3(1, 0, 0, 1) },
    new Contribution3[] { new Contribution3(2, 1, 1, 0), new Contribution3(2, 1, 0, 1), new Contribution3(2, 0, 1, 1), new Contribution3(3, 1, 1, 1) },
    new Contribution3[] { new Contribution3(1, 1, 0, 0), new Contribution3(1, 0, 1, 0), new Contribution3(1, 0, 0, 1), new Contribution3(2, 1, 1, 0), new Contribution3(2, 1, 0, 1), new Contribution3(2, 0, 1, 1)}
    };

    private static readonly Contribution4[][] contributions4D =
    {
    new Contribution4[] { new Contribution4(0, 0, 0, 0, 0), new Contribution4(1, 1, 0, 0, 0), new Contribution4(1, 0, 1, 0, 0), new Contribution4(1, 0, 0, 1, 0), new Contribution4(1, 0, 0, 0, 1) },
    new Contribution4[] { new Contribution4(3, 1, 1, 1, 0), new Contribution4(3, 1, 1, 0, 1), new Contribution4(3, 1, 0, 1, 1), new Contribution4(3, 0, 1, 1, 1), new Contribution4(4, 1, 1, 1, 1) },
    new Contribution4[] { new Contribution4(1, 1, 0, 0, 0), new Contribution4(1, 0, 1, 0, 0), new Contribution4(1, 0, 0, 1, 0), new Contribution4(1, 0, 0, 0, 1), new Contribution4(2, 1, 1, 0, 0), new Contribution4(2, 1, 0, 1, 0), new Contribution4(2, 1, 0, 0, 1), new Contribution4(2, 0, 1, 1, 0), new Contribution4(2, 0, 1, 0, 1), new Contribution4(2, 0, 0, 1, 1) },
    new Contribution4[] { new Contribution4(3, 1, 1, 1, 0), new Contribution4(3, 1, 1, 0, 1), new Contribution4(3, 1, 0, 1, 1), new Contribution4(3, 0, 1, 1, 1), new Contribution4(2, 1, 1, 0, 0), new Contribution4(2, 1, 0, 1, 0), new Contribution4(2, 1, 0, 0, 1), new Contribution4(2, 0, 1, 1, 0), new Contribution4(2, 0, 1, 0, 1), new Contribution4(2, 0, 0, 1, 1) }
    };

    public OpenSimplexNoise()
    : this(DateTime.Now.Ticks)
    {
    }

    //Initializes the class using a permutation array generated from a 64-bit seed.
    //Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array)
    //Uses a simple 64-bit LCG.
    public OpenSimplexNoise(long seed)
    {
    perm = new byte[256];
    perm2D = new byte[256];
    perm3D = new byte[256];
    perm4D = new byte[256];
    var source = new byte[256];
    for (int i = 0; i < 256; i++)
    {
    source[i] = (byte)i;
    }
    seed = seed * 6364136223846793005L + 1442695040888963407L;
    seed = seed * 6364136223846793005L + 1442695040888963407L;
    seed = seed * 6364136223846793005L + 1442695040888963407L;
    for (int i = 255; i >= 0; i--)
    {
    seed = seed * 6364136223846793005L + 1442695040888963407L;
    int r = (int)((seed + 31) % (i + 1));
    if (r < 0)
    {
    r += (i + 1);
    }
    perm[i] = source[r];
    perm2D[i] = (byte)((perm[i] % 8) * 2);
    perm3D[i] = (byte)((perm[i] % 12) * 3);
    perm4D[i] = (byte)((perm[i] % 64) * 4);
    source[r] = source[i];
    }
    }

    public double Evaluate(double x, double y)
    {
    //Place input coordinates onto grid.
    var stretchOffset = (x + y) * STRETCH_2D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;

    //Floor to get grid coordinates of rhombus (stretched square) super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;

    //Skew out to get actual coordinates of rhombus origin. We'll need these later.
    var squishOffset = (xsb + ysb) * SQUISH_2D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;

    //Compute grid coordinates relative to rhombus origin.
    var xins = xs - xsb;
    var yins = ys - ysb;

    //Sum those together to get a value that determines which region we're in.
    var inSum = xins + yins;

    Contribution2[] contributions;
    if (inSum > 1) //We're inside the triangle (2-Simplex) at (0,0)
    {
    contributions = contributions2D[0];
    }
    else //We're inside the triangle (2-Simplex) at (1,1)
    {
    contributions = contributions2D[1];
    }

    double value = 0;
    foreach (var c in contributions)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    var attn = 2 - dx * dx - dy * dy;
    if (attn > 0)
    {
    var px = xsb + c.xsb;
    var py = ysb + c.ysb;

    var i = perm2D[(perm[px & 0xFF] + py) & 0xFF];
    var valuePart = gradients2D[i] * dx + gradients2D[i + 1] * dy;

    attn *= attn;
    value += attn * attn * valuePart;
    }
    }

    return value / NORM_2D;
    }

    public double Evaluate(double x, double y, double z)
    {
    //Place input coordinates on simplectic honeycomb.
    var stretchOffset = (x + y + z) * STRETCH_3D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;
    var zs = z + stretchOffset;

    //Floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;
    var zsb = zs > 0 ? (int)zs : (int)zs - 1;

    //Skew out to get actual coordinates of rhombohedron origin. We'll need these later.
    var squishOffset = (xsb + ysb + zsb) * SQUISH_3D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;

    //Compute simplectic honeycomb coordinates relative to rhombohedral origin.
    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;

    //Sum those together to get a value that determines which region we're in.
    var inSum = xins + yins + zins;

    Contribution3[] contributions;
    if (inSum <= 1) //We're inside the tetrahedron (3-Simplex) at (0,0,0)
    {
    contributions = contributions3D[0];
    }
    else if (inSum >= 2) //We're inside the tetrahedron (3-Simplex) at (1,1,1)
    {
    contributions = contributions3D[1];
    }
    else //We're inside the octahedron (Rectified 3-Simplex) in between.
    {
    contributions = contributions3D[2];
    }

    double value = 0;
    foreach (var c in contributions)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    var dz = dz0 + c.dz;
    var attn = 2 - dx * dx - dy * dy - dz * dz;
    if (attn > 0)
    {
    var px = xsb + c.xsb;
    var py = ysb + c.ysb;
    var pz = zsb + c.zsb;

    var i = perm3D[(perm[(perm[px & 0xFF] + py) & 0xFF] + pz) & 0xFF];
    var valuePart = gradients3D[i] * dx + gradients3D[i + 1] * dy + gradients3D[i + 2] * dz;

    attn *= attn;
    value += attn * attn * valuePart;
    }
    }

    return value / NORM_3D;
    }

    public double Evaluate(double x, double y, double z, double w)
    {
    //Place input coordinates on simplectic honeycomb.
    var stretchOffset = (x + y + z + w) * STRETCH_4D;
    var xs = x + stretchOffset;
    var ys = y + stretchOffset;
    var zs = z + stretchOffset;
    var ws = w + stretchOffset;

    //Floor to get simplectic honeycomb coordinates of rhombo-hypercube super-cell origin.
    var xsb = xs > 0 ? (int)xs : (int)xs - 1;
    var ysb = ys > 0 ? (int)ys : (int)ys - 1;
    var zsb = zs > 0 ? (int)zs : (int)zs - 1;
    var wsb = ws > 0 ? (int)ws : (int)ws - 1;

    //Skew out to get actual coordinates of stretched rhombo-hypercube origin. We'll need these later.
    var squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D;
    var xb = xsb + squishOffset;
    var yb = ysb + squishOffset;
    var zb = zsb + squishOffset;
    var wb = wsb + squishOffset;

    //Positions relative to origin point.
    var dx0 = x - xb;
    var dy0 = y - yb;
    var dz0 = z - zb;
    var dw0 = w - wb;

    //Compute simplectic honeycomb coordinates relative to rhombo-hypercube origin.
    var xins = xs - xsb;
    var yins = ys - ysb;
    var zins = zs - zsb;
    var wins = ws - wsb;

    //Sum those together to get a value that determines which region we're in.
    var inSum = xins + yins + zins + wins;

    Contribution4[] contributions;
    if (inSum <= 1) // We're inside the pentachoron (4-Simplex) at (0,0,0,0)
    {
    contributions = contributions4D[0];
    }
    else if (inSum >= 3) //We're inside the pentachoron (4-Simplex) at (1,1,1,1)
    {
    contributions = contributions4D[1];
    }
    else if (inSum <= 2) // We're inside the first dispentachoron (Rectified 4-Simplex)
    {
    contributions = contributions4D[2];
    }
    else // We're inside the second dispentachoron (Rectified 4-Simplex)
    {
    contributions = contributions4D[3];
    }

    double value = 0;
    foreach (var c in contributions)
    {
    var dx = dx0 + c.dx;
    var dy = dy0 + c.dy;
    var dz = dz0 + c.dz;
    var dw = dw0 + c.dw;
    var attn = 2 - dx * dx - dy * dy - dz * dz - dw * dw;
    if (attn > 0)
    {
    var px = xsb + c.xsb;
    var py = ysb + c.ysb;
    var pz = zsb + c.zsb;
    var pw = wsb + c.wsb;

    var i = perm4D[(perm[(perm[(perm[px & 0xFF] + py) & 0xFF] + pz) & 0xFF] + pw) & 0xFF];
    var valuePart = gradients4D[i] * dx + gradients4D[i + 1] * dy + gradients4D[i + 2] * dz + gradients4D[i + 3] * dw;

    attn *= attn;
    value += attn * attn * valuePart;
    }
    }

    return value / NORM_4D;
    }

    private struct Contribution2
    {
    public readonly double dx, dy;
    public readonly int xsb, ysb;

    public Contribution2(double multiplier, int xsb, int ysb)
    {
    dx = -xsb - multiplier * SQUISH_2D;
    dy = -ysb - multiplier * SQUISH_2D;
    this.xsb = xsb;
    this.ysb = ysb;
    }
    }

    private struct Contribution3
    {
    public readonly double dx, dy, dz;
    public readonly int xsb, ysb, zsb;

    public Contribution3(double multiplier, int xsb, int ysb, int zsb)
    {
    dx = -xsb - multiplier * SQUISH_3D;
    dy = -ysb - multiplier * SQUISH_3D;
    dz = -zsb - multiplier * SQUISH_3D;
    this.xsb = xsb;
    this.ysb = ysb;
    this.zsb = zsb;
    }
    }

    private struct Contribution4
    {
    public readonly double dx, dy, dz, dw;
    public readonly int xsb, ysb, zsb, wsb;

    public Contribution4(double multiplier, int xsb, int ysb, int zsb, int wsb)
    {
    dx = -xsb - multiplier * SQUISH_4D;
    dy = -ysb - multiplier * SQUISH_4D;
    dz = -zsb - multiplier * SQUISH_4D;
    dw = -wsb - multiplier * SQUISH_4D;
    this.xsb = xsb;
    this.ysb = ysb;
    this.zsb = zsb;
    this.wsb = wsb;
    }
    }
    }
    }