private void AddSingle <T1>(CombinerFunc <T1> combinerAction, CombinerFunc <T1> switchedCombinerAction)
 {
     this._combinerActions[new TypeTuple(typeof(T1), null)] =
         (object x, object y, out object v) => combinerAction((T1)x, out v);
     this._combinerActions[new TypeTuple(null, typeof(T1))] =
         (object x, object y, out object v) => switchedCombinerAction((T1)y, out v);
 }
Example #2
0
        public static float Get3D(float x, float y, float z, CombinerFuncEnum combinerFunc, DistanceFuncEnum distanceFunc)
        {
            DistanceFunc _dFunc = null;

            switch (distanceFunc)
            {
            case DistanceFuncEnum.Euclidean:
                _dFunc = EuclidianDistanceFunc;
                break;

            case DistanceFuncEnum.Manhattan:
                _dFunc = ManhattanDistanceFunc;
                break;

            case DistanceFuncEnum.Chebyshev:
                _dFunc = ChebyshevDistanceFunc;
                break;
            }

            CombinerFunc _cFunc = null;

            switch (combinerFunc)
            {
            case CombinerFuncEnum.D1:
                _cFunc = CombinerFunc1;                // i => i[0];
                break;

            case CombinerFuncEnum.D2MinusD1:
                _cFunc = CombinerFunc2;                //i => i[1] - i[0];
                break;

            case CombinerFuncEnum.D3MinusD1:
                _cFunc = CombinerFunc3;                //i => i[2] - i[0];
                break;
            }

            return(noise3d(new Vector3(x, y, z), _cFunc, _dFunc));
        }
 private void AddSingle <T1, T2>(CombinerFunc <T1, T2> combinerAction)
 {
     this._combinerActions[new TypeTuple(typeof(T1), typeof(T2))] =
         (object x, object y, out object v) => combinerAction((T1)x, (T2)y, out v);
 }
 private void AddSingle(CombinerFunc combinerAction)
 {
     this._combinerActions[new TypeTuple(null, null)] = (object x, object y, out object v) => combinerAction(out v);
 }
Example #5
0
 public WorleyNoise(int Seed, DistanceFunc DFunc, CombinerFunc CFunc)
     : this(Seed)
 {
     DistanceFunction = DFunc;
     CombinerFunction = CFunc;
 }
Example #6
0
        static float noise2d(Vector2 input, CombinerFunc combinerFunc, DistanceFunc distanceFunc)
        {
            uint    lastRandom;
            uint    numberFeaturePoints;
            Vector2 randomDiff   = new Vector2(0, 0);
            Vector2 featurePoint = new Vector2(0, 0);

            int cubeX, cubeY;

            for (var i = 0; i < DistanceArray.Length; i++)
            {
                DistanceArray[i] = 6666;
            }

            var evalCubeX = (int)(Mathf.Floor(input.x));
            var evalCubeY = (int)(Mathf.Floor(input.y));

            for (var i = -1; i < 2; ++i)
            {
                for (var j = -1; j < 2; ++j)
                {
                    cubeX = evalCubeX + i;
                    cubeY = evalCubeY + j;

                    //2. Generate a reproducible random number generator for the cube
                    lastRandom = lcgRandom(hash((cubeX + Seed) & 0xffffffff, (cubeY) & 0xffffffff));
                    //3. Determine how many feature points are in the cube
                    numberFeaturePoints = (uint)probLookup(lastRandom);
                    //4. Randomly place the feature points in the cube
                    for (var l = 0; l < numberFeaturePoints; ++l)
                    {
                        lastRandom   = lcgRandom(lastRandom);
                        randomDiff.x = (float)lastRandom / 0x100000000;

                        lastRandom   = lcgRandom(lastRandom);
                        randomDiff.y = (float)lastRandom / 0x100000000;

                        featurePoint = new Vector2(randomDiff.x + cubeX, randomDiff.y + cubeY);

                        //5. Find the feature point closest to the evaluation point.
                        //This is done by inserting the distances to the feature points into a sorted list
                        float v = distanceFunc(input, featurePoint);
                        insert(DistanceArray, v);
                    }
                    //6. Check the neighboring cubes to ensure their are no closer evaluation points.
                    // This is done by repeating steps 1 through 5 above for each neighboring cube
                }
            }

            var color = combinerFunc(DistanceArray);

            if (color < 0)
            {
                color = 0;
            }
            if (color > 1)
            {
                color = 1;
            }

            return(color);



            /*
             * //Declare some values for later use
             * uint lastRandom, numberFeaturePoints;
             * Vector2 randomDiff, featurePoint;
             * int cubeX, cubeY;
             *
             * float[] distanceArray = new float[3];
             *
             * //Initialize values in distance array to large values
             * for (int i = 0; i < distanceArray.Length; i++)
             *      distanceArray[i] = 6666;
             *
             * //1. Determine which cube the evaluation point is in
             * int evalCubeX = (int)Mathf.Floor(input.x);
             * int evalCubeY = (int)Mathf.Floor(input.y);
             *
             * for (int i = -1; i < 2; ++i)
             * {
             *      for (int j = -1; j < 2; ++j)
             *      {
             *              cubeX = evalCubeX + i;
             *              cubeY = evalCubeY + j;
             *
             *              //2. Generate a reproducible random number generator for the cube
             *              lastRandom = lcgRandom(hash((uint)(cubeX + inSeed), (uint)(cubeY)));
             *
             *              //3. Determine how many feature points are in the cube
             *              numberFeaturePoints = probLookup(lastRandom);
             *              //4. Randomly place the feature points in the cube
             *              for (uint l = 0; l < numberFeaturePoints; ++l)
             *              {
             *                      lastRandom = lcgRandom(lastRandom);
             *                      randomDiff.x = (float)lastRandom / 0x100000000;
             *
             *                      lastRandom = lcgRandom(lastRandom);
             *                      randomDiff.y = (float)lastRandom / 0x100000000;
             *
             *                      featurePoint = new Vector2(randomDiff.x + (float)cubeX, randomDiff.y + (float)cubeY);
             *
             *                      //5. Find the feature point closest to the evaluation point.
             *                      //This is done by inserting the distances to the feature points into a sorted list
             *                      insert(distanceArray, DistanceFunc2(input, featurePoint));
             *              }
             *              //6. Check the neighboring cubes to ensure their are no closer evaluation points.
             *              // This is done by repeating steps 1 through 5 above for each neighboring cube
             *      }
             * }
             *
             * return Mathf.Clamp01(CombineFunc(distanceArray));
             */
        }
Example #7
0
        static float noise3d(Vector3 input, CombinerFunc combinerFunc, DistanceFunc distanceFunc)
        {
//			var value = 0;

            uint    lastRandom;
            uint    numberFeaturePoints;
            Vector3 randomDiff   = new Vector3(0, 0, 0);
            Vector3 featurePoint = new Vector3(0, 0, 0);

            int cubeX, cubeY, cubeZ;

            for (var i = 0; i < DistanceArray.Length; i++)
            {
                DistanceArray[i] = 6666;
            }

            var evalCubeX = (int)(Mathf.Floor(input.x));
            var evalCubeY = (int)(Mathf.Floor(input.y));
            var evalCubeZ = (int)(Mathf.Floor(input.z));

            for (var i = -1; i < 2; ++i)
            {
                for (var j = -1; j < 2; ++j)
                {
                    for (var k = -1; k < 2; ++k)
                    {
                        cubeX = evalCubeX + i;
                        cubeY = evalCubeY + j;
                        cubeZ = evalCubeZ + k;

                        //2. Generate a reproducible random number generator for the cube
                        lastRandom = lcgRandom(hash((cubeX + Seed) & 0xffffffff, (cubeY) & 0xffffffff, (cubeZ) & 0xffffffff));
                        //3. Determine how many feature points are in the cube
                        numberFeaturePoints = (uint)probLookup(lastRandom);
                        //4. Randomly place the feature points in the cube
                        for (var l = 0; l < numberFeaturePoints; ++l)
                        {
                            lastRandom   = lcgRandom(lastRandom);
                            randomDiff.x = (float)lastRandom / 0x100000000;

                            lastRandom   = lcgRandom(lastRandom);
                            randomDiff.y = (float)lastRandom / 0x100000000;

                            lastRandom   = lcgRandom(lastRandom);
                            randomDiff.z = (float)lastRandom / 0x100000000;

                            featurePoint = new Vector3(randomDiff.x + cubeX, randomDiff.y + cubeY, randomDiff.z + cubeZ);

                            //5. Find the feature point closest to the evaluation point.
                            //This is done by inserting the distances to the feature points into a sorted list
                            float v = distanceFunc(input, featurePoint);
                            insert(DistanceArray, v);
                        }
                        //6. Check the neighboring cubes to ensure their are no closer evaluation points.
                        // This is done by repeating steps 1 through 5 above for each neighboring cube
                    }
                }
            }

            var color = combinerFunc(DistanceArray);

            if (color < 0)
            {
                color = 0;
            }
            if (color > 1)
            {
                color = 1;
            }

            return(color);
        }
Example #8
0
 public WorleyNoise(int Seed, DistanceFunc DFunc, CombinerFunc CFunc) :
     this(Seed)
 {
     DistanceFunction = DFunc;
     CombinerFunction = CFunc;
 }