private void OnGUI()
        {
            _noiseType = (NoiseType)EditorGUILayout.EnumPopup("NoiseType", _noiseType);

            if (_texOutputOptions == null)
            {
                _texOutputOptions = new NoiseTextureOutputOptions();
            }

            _texOutputOptions.OnGUI();

            if (!_noiseOptions.ContainsKey(_noiseType))
            {
                _noiseOptions.Add(_noiseType, NoiseEditorUtil.CreateNoiseOptionsByType(_noiseType));
            }

            _noiseOptions[_noiseType].OnGUI();


            if (GUILayout.Button("Generate"))
            {
                var      noiseOptions = _noiseOptions[_noiseType];
                INoise2D noise        = noiseOptions.CreateNoise(_texOutputOptions);
                _generatedTexture = _texOutputOptions.ExportNoiseTo(noise);
            }

            if (_generatedTexture != null)
            {
                var rect = EditorGUILayout.GetControlRect(GUILayout.Width(256), GUILayout.Height(256));
                GUI.DrawTexture(rect, _generatedTexture);
            }
        }
Exemple #2
0
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(this.distorter.Noise(sourceNoise, x, y).ConvertRange(
                       this.sourceNoiseStart, this.sourceNoiseEnd, this.resultNoiseStart, this.resultNoiseEnd));
        }
Exemple #3
0
        public DistortedNoise2D(INoise2D noise, INoiseDistorter2D distorter)
        {
            Contracts.Requires.That(noise != null);
            Contracts.Requires.That(distorter != null);

            this.noise     = noise;
            this.distorter = distorter;
        }
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            double result = 0;

            foreach (var distorter in this.distorters)
            {
                result += distorter.Noise(sourceNoise, x, y);
            }

            return(result);
        }
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            double result = this.distorter.Noise(sourceNoise, x, y);

            int weight = 2;

            for (int octave = 2; octave <= this.numberOfOctaves; octave++)
            {
                result += this.distorter.Noise(sourceNoise, x * weight, y * weight) / weight;
                weight *= 2;
            }

            return(result);
        }
        public Texture2D ExportNoiseTo(INoise2D noise)
        {
            var tex = noise.CreateTexture(new NoiseTextureGenerateOptions()
            {
                width    = imageSize.x,
                height   = imageSize.y,
                cellSize = cellSize
            });
            var binary = tex.EncodeToJPG();

            if (_fileName == null)
            {
                _fileName = "nosie.jpg";
            }
            var outPath = Path.Combine(outputDir, _fileName);

            File.WriteAllBytes(outPath, binary);
            return(tex);
        }
Exemple #7
0
        public Terrain(float width, float height, int divisions , INoise2D noise)
            : base()
        {
            // init the internal variables
            m_width = width;
            m_height = height;

            // calc the number of the vertex in the grid
            int numVertex = (divisions + 1) * (divisions + 1);

            // init the poligons of the terrain
            Vertex[,] verts = new Vertex[(divisions + 1), (divisions + 1)];

            // calc the positions of the vertex
            for (int y = 0; y <= divisions; y++)
            {
                for (int x = 0; x <= divisions; x++)
                {
                    float p_x=(float)x/(divisions+1)*width;
                    float p_z=(float)y/(divisions+1)*height;

                    float u=(float)x/(divisions+1);
                    float v=(float)y/(divisions+1);
                    float p_y = noise.GetValue( v, u );

                    verts[x,y] = new Vertex(p_x, p_y, p_z, 0, 0, 0, v, u);
                }
            }

            for (int y = 0; y < divisions; y++)
            {
                for (int x = 0; x < divisions; x++)
                {
                    // add the polygons
                    this.AddPolygon(verts[x,y], verts[x+1,y], verts[x,y+1], false);
                    this.AddPolygon(verts[x,y+1], verts[x+1,y+1], verts[x+1,y], false);
                }
            }
        }
Exemple #8
0
        public SkyIslandMapChunkPopulator(
            SkyIslandMapPopulatorConfig mapsConfig,
            IStageBounds stageBounds,
            IFactory <int, INoise2D> multiNoise)
        {
            Contracts.Requires.That(mapsConfig != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(multiNoise != null);

            this.mapsConfig = mapsConfig;

            // using the lesser of the 2 dimensions ensures the radial gradient doesn't clip early out of bounds
            var stageOverheadDimensions = stageBounds.InOverheadChunks.Dimensions;

            this.halfStageLength = Math.Min(stageOverheadDimensions.X, stageOverheadDimensions.Y) / 2.0;
            this.radiusStart     = this.halfStageLength * this.mapsConfig.SelectionGradientStartDistancePercent;

            this.shapeNoise    = multiNoise.Create(SkyIslandNoiseSubSeed.ShapeMap);
            this.baselineNoise = multiNoise.Create(SkyIslandNoiseSubSeed.BaselineMap);
            this.mountainNoise = multiNoise.Create(SkyIslandNoiseSubSeed.MountainMap);
            this.topNoise      = multiNoise.Create(SkyIslandNoiseSubSeed.TopMap);
            this.bottomNoise   = multiNoise.Create(SkyIslandNoiseSubSeed.BottomMap);
        }
Exemple #9
0
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(this.distorter.Noise(sourceNoise, x + this.xShift, y + this.yShift));
        }
Exemple #10
0
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(this.distorter.Noise(sourceNoise, x, y) * this.amplitude);
        }
 /// <summary>
 /// Sample two-dimensional noise.
 /// </summary>
 public static float Sample(this INoise2D noise, in Vector position)
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(this.distorter.Noise(sourceNoise, x * this.xFrequency, y * this.yFrequency));
        }
 public static void Noise(INoise2D sourceNoise)
 {
     Contracts.Requires.That(sourceNoise != null);
 }
Exemple #14
0
 public TransformedNoise2D(INoise2D sourceNoise, float frequency, float amplitude)
 {
     _sourceNoise = sourceNoise;
 }
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(sourceNoise.Noise(x, y));
        }
Exemple #16
0
        /// <inheritdoc />
        public double Noise(INoise2D sourceNoise, double x, double y)
        {
            INoiseDistorter2DContracts.Noise(sourceNoise);

            return(this.distorter.Noise(sourceNoise, x, y).Clamp(this.min, this.max));
        }