コード例 #1
0
ファイル: Noise3D.cs プロジェクト: warrocky/FightLands
        /// <summary>
        /// Method that returns a Turbulence noise with the speficied parameters that has a customizable filter.
        /// </summary>
        /// <param name="period">Size of the noise.</param>
        /// <param name="steps">Detail of the noise</param>
        /// <param name="seed">The seed used</param>
        /// <returns>A SumNoise with several noises.</returns>
        public static Noise3D TurbulenceNoise(float period, int steps, Point3 periodLoop, int seed)
        {
            SumNoise3D sumNoise = new SumNoise3D();
            Random     rdm      = new Random(seed);

            LoopableNoise3D noise;

            float[] weights = new float[steps];
            weights[0] = 0.5f;
            float weightSum = 0.5f;

            for (int i = 1; i < steps; i++)
            {
                weights[i] = weights[i - 1] * 0.5f;
                weightSum += weights[i];
            }

            noiseSumFunction simpleSum = (float a, float b) => a + b;
            noiseSumFunction lastFunc  = (float a, float b) => ((a + b) - 0.5f) * 2f;

            //float weight;
            for (int i = 0; i < steps; i++)
            {
                noise = new LoopableNoise3D(rdm.Next(), period, periodLoop);
                //float weight = weights[i] + (weights[i] / weightSum) * (1f - weightSum);
                float weight = weights[i] / weightSum;

                noise.filter = (float value, Vector3 position) => Math.Abs(value) * weight;
                //noise.filter = (float value, Vector2 position) => (Math.Abs(value) - 0.5f)*2f*weight;

                //o filtro do ultimo noise coloca os valores no intervalo [-1,1]
                if (i != steps - 1)
                {
                    sumNoise.addNoise(noise, (float a, float b) => a + b);
                }
                else
                {
                    sumNoise.addNoise(noise, (float a, float b) => ((a + b) - 0.5f) * 2f);
                }



                period       *= 0.5f;
                periodLoop.X *= 2;
                periodLoop.Y *= 2;
                periodLoop.Z *= 2;
            }

            //sumNoise.filter = (float a, Vector2 b) => { return (a + 1f) / 2f; };
            sumNoise.filter = (float a, Vector3 b) => a;
            return(sumNoise);
        }
コード例 #2
0
ファイル: Noise3D.cs プロジェクト: warrocky/FightLands
        public static Noise3D RegularNoise(float period, int steps, Point3 periodLoop, int seed)
        {
            if (steps == 0)
            {
                throw new Exception("Can't create a noise regular noise with 0 steps");
            }

            SumNoise3D sumNoise = new SumNoise3D();
            Random     rdm      = new Random(seed);

            LoopableNoise3D noise;

            float[] weights = new float[steps];
            weights[0] = 0.5f;
            float weightSum = 0.5f;

            for (int i = 1; i < steps; i++)
            {
                weights[i] = weights[i - 1] * 0.5f;
                weightSum += weights[i];
            }

            //float weight;
            Noise3D.noiseSumFunction simpleSum = (float a, float b) => { return(a + b); };
            for (int j = 0; j < steps; j++)
            {
                noise = new LoopableNoise3D(rdm.Next(), period, periodLoop);
                float weight = weights[j] / weightSum;
                noise.filter = (float value, Vector3 position) => { return(value * (weight)); };

                sumNoise.addNoise(noise, simpleSum);


                period       *= 0.5f;
                periodLoop.X *= 2;
                periodLoop.Y *= 2;
                periodLoop.Z *= 2;
            }

            return(sumNoise);
        }
コード例 #3
0
ファイル: Noise3D.cs プロジェクト: warrocky/FightLands
        /// <summary>
        /// Method that returns a Turbulence noise with the speficied parameters that has a customizable filter.
        /// </summary>
        /// <param name="period">Size of the noise.</param>
        /// <param name="steps">Detail of the noise</param>
        /// <param name="seed">The seed used</param>
        /// <returns>A SumNoise with several noises.</returns>
        public static Noise3D TurbulenceNoise(float period, int steps, Point3 periodLoop, int seed)
        {
            SumNoise3D sumNoise = new SumNoise3D();
            Random rdm = new Random(seed);

            LoopableNoise3D noise;

            float[] weights = new float[steps];
            weights[0] = 0.5f;
            float weightSum = 0.5f;

            for (int i = 1; i < steps; i++)
            {
                weights[i] = weights[i - 1] * 0.5f;
                weightSum += weights[i];
            }

            noiseSumFunction simpleSum = (float a, float b) => a + b;
            noiseSumFunction lastFunc = (float a, float b) => ((a + b) - 0.5f) * 2f;
            //float weight;
            for (int i = 0; i < steps; i++)
            {
                noise = new LoopableNoise3D(rdm.Next(), period, periodLoop);
                //float weight = weights[i] + (weights[i] / weightSum) * (1f - weightSum);
                float weight = weights[i] / weightSum;

                noise.filter = (float value, Vector3 position) => Math.Abs(value) * weight;
                //noise.filter = (float value, Vector2 position) => (Math.Abs(value) - 0.5f)*2f*weight;

                //o filtro do ultimo noise coloca os valores no intervalo [-1,1]
                if (i != steps - 1)
                {
                    sumNoise.addNoise(noise, (float a, float b) => a + b);
                }
                else
                {
                    sumNoise.addNoise(noise, (float a, float b) => ((a + b) - 0.5f) * 2f);
                }

                period *= 0.5f;
                periodLoop.X *= 2;
                periodLoop.Y *= 2;
                periodLoop.Z *= 2;
            }

            //sumNoise.filter = (float a, Vector2 b) => { return (a + 1f) / 2f; };
            sumNoise.filter = (float a, Vector3 b) => a;
            return sumNoise;
        }
コード例 #4
0
ファイル: Noise3D.cs プロジェクト: warrocky/FightLands
        public static Noise3D RegularNoise(float period, int steps, Point3 periodLoop, int seed)
        {
            if (steps == 0)
                throw new Exception("Can't create a noise regular noise with 0 steps");

            SumNoise3D sumNoise = new SumNoise3D();
            Random rdm = new Random(seed);

            LoopableNoise3D noise;

            float[] weights = new float[steps];
            weights[0] = 0.5f;
            float weightSum = 0.5f;

            for (int i = 1; i < steps; i++)
            {
                weights[i] = weights[i - 1] * 0.5f;
                weightSum += weights[i];
            }

            //float weight;
            Noise3D.noiseSumFunction simpleSum = (float a, float b) => { return a + b; };
            for (int j = 0; j < steps; j++)
            {
                noise = new LoopableNoise3D(rdm.Next(), period, periodLoop);
                float weight = weights[j] / weightSum;
                noise.filter = (float value, Vector3 position) => { return value * (weight); };

                sumNoise.addNoise(noise, simpleSum);

                period *= 0.5f;
                periodLoop.X *= 2;
                periodLoop.Y *= 2;
                periodLoop.Z *= 2;
            }

            return sumNoise;
        }