コード例 #1
0
        /// <summary>
        /// Ridged multifractal value. Range 0.0 : 1.0
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="opts"></param>
        /// <returns></returns>
        public float Ridged(Vector3 pos, NoiseOptions opts)
        {
            //Setup
            double total     = 0.0f;
            float  amplitude = 0.5f;
            double previous  = 1.0f;

            float freq = opts.frequency;

            //FastRandom rng = new FastRandom (opts.seed);

            //Value is between -1 an 1
            for (int i = 0; i < opts.octaves; i++)
            {
                //int sx = rng.Next(-10000, 10000);
                //int sy = rng.Next(-10000, 10000);
                //int sz = rng.Next(-10000, 10000);

                double value = Noise(
                    (pos.x + opts.offset.x) * freq - opts.seed,
                    (pos.y + opts.offset.y) * freq - opts.seed,
                    (pos.z + opts.offset.z) * freq - opts.seed
                    );

                total     += Ridge(value) * amplitude * previous;
                previous   = value;
                freq      *= opts.lacunarity;
                amplitude *= opts.persistence;
            }

            //Return the processed value
            return((float)total);
        }
コード例 #2
0
        /// <summary>
        /// FBM Sum value, Range -1.0 : 1.0
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="opts"></param>
        /// <returns></returns>
        public float Sum(Vector3 pos, NoiseOptions opts)
        {
            //Setup
            double total        = 0.0f;
            float  maxAmplitude = 0.0f;
            float  amplitude    = 1.0f;
            float  frequency    = opts.frequency;
            float  persistence  = opts.persistence;

            //FastRandom rng = new FastRandom (opts.seed);

            //Value is between -1 an 1
            for (int i = 0; i < opts.octaves; i++)
            {
                //int sx = rng.Next(-10000, 10000);
                //int sy = rng.Next(-10000, 10000);
                //int sz = rng.Next(-10000, 10000);

                total += Noise(
                    (pos.x + opts.offset.x) * frequency - opts.seed,
                    (pos.y + opts.offset.y) * frequency - opts.seed,
                    (pos.z + opts.offset.z) * frequency - opts.seed
                    ) * amplitude;
                frequency    *= opts.lacunarity;
                maxAmplitude += amplitude;
                amplitude    *= persistence;
            }
            float noise = ((float)total) / maxAmplitude;

            //Return the processed value
            return(noise);
        }
コード例 #3
0
ファイル: INoise.cs プロジェクト: oznogongames/Spaceworks
 public NoiseOptions(NoiseOptions other)
 {
     this.octaves     = other.octaves;
     this.persistence = other.persistence;
     this.frequency   = other.frequency;
     this.lacunarity  = other.lacunarity;
     this.offset      = other.offset;
 }
コード例 #4
0
            private void FillTexture(Texture2D t, Face face, NoiseOptions opts, float discrete = -1000)
            {
                float  w    = t.width - 1;
                float  h    = t.height - 1;
                Perlin perl = new Perlin();

                for (int i = 0; i <= w; i++)
                {
                    for (int j = 0; j <= h; j++)
                    {
                        float xp = 0, yp = 0, zp = 0;

                        switch (face)
                        {
                        case Face.Top:
                            yp = 1;
                            xp = (i / w) * 2 - 1;
                            zp = 1 - (j / h) * 2;
                            break;

                        case Face.Bottom:
                            yp = -1;
                            xp = (i / w) * 2 - 1;
                            zp = (j / h) * 2 - 1;
                            break;

                        case Face.Left:
                            xp = -1;
                            zp = 1 - (i / w) * 2;
                            yp = 1 - (j / h) * 2;
                            break;

                        case Face.Back:
                            zp = -1;
                            xp = (i / w) * 2 - 1;
                            yp = 1 - (j / h) * 2;
                            break;

                        case Face.Right:
                            xp = 1;
                            zp = (i / w) * 2 - 1;
                            yp = 1 - (j / h) * 2;
                            break;

                        case Face.Front:
                            zp = 1;
                            xp = 1 - (i / w) * 2;
                            yp = 1 - (j / h) * 2;
                            break;
                        }

                        Vector3 pos = IMeshService.Spherify(new Vector3(xp, yp, zp));

                        float n = perl.Sum(pos, opts);
                        t.SetPixel(i, j, (discrete <= 1 && discrete >= -1) ? (n < discrete ? a : b) : Color.Lerp(a, b, (n + 1) * 0.5f));
                    }
                }
            }
コード例 #5
0
            public void Draw(NoiseOptions opts, float discrete = -1000)
            {
                //Ensure textures exist
                TestExistance();

                //Generate Textures
                FillTexture(top, Face.Top, opts, discrete);
                FillTexture(bottom, Face.Bottom, opts, discrete);
                FillTexture(left, Face.Left, opts, discrete);
                FillTexture(right, Face.Right, opts, discrete);
                FillTexture(front, Face.Front, opts, discrete);
                FillTexture(back, Face.Back, opts, discrete);

                //Apply textures
                top.Apply();
                bottom.Apply();
                left.Apply();
                right.Apply();
                front.Apply();
                back.Apply();

                //Draw Textures
                GUILayout.BeginVertical();

                GUILayout.Label(top);

                GUILayout.BeginHorizontal();

                GUILayout.Label(back);
                GUILayout.Label(right);
                GUILayout.Label(front);
                GUILayout.Label(left);

                GUILayout.EndHorizontal();

                GUILayout.Label(bottom);

                GUILayout.EndVertical();
            }