Beispiel #1
0
    public static float[,] GenerateSimplexNoiseMap(int mapWidth, int mapHeight, NoiseSettings settings, Vector2 sampleCentre)
    {
        float[,] noiseMap = new float[mapWidth, mapHeight];
        OpenSimplex2F simplexNoise = new OpenSimplex2F(settings.seed);

        System.Random prng    = new System.Random(settings.seed);
        float         offsetX = prng.Next(-100000, 100000) + settings.offset.x + sampleCentre.x;
        float         offsetY = prng.Next(-100000, 100000) - settings.offset.y - sampleCentre.y;
        Vector2       offset  = new Vector2(offsetX, offsetY);

        float halfWidth = mapWidth / 2f;
        float halHeight = mapHeight / 2f;

        for (int y = 0; y < mapHeight; ++y)
        {
            for (int x = 0; x < mapWidth; ++x)
            {
                float sampleX = (x - halfWidth + offset.x) / (settings.scale * 10f);
                float sampleY = (y - halHeight + offset.y) / (settings.scale * 10f);

                float noiseHeight = (float)simplexNoise.Noise2(sampleX, sampleY) * 2 - 1;
                noiseMap[x, y] = noiseHeight;
            }
        }


        return(noiseMap);
    }
Beispiel #2
0
        public float[,] Generate()
        {
            OpenSimplex2F noiseGenerator = new OpenSimplex2F(properties.seed);

            Vector2[] octaveOffsets = GenerateRandomOctaveOffsets();
            float     halfWidth     = properties.sizeBound / 2.0f;
            float     halfHeight    = properties.sizeBound / 2.0f;

            float minNoiseHeight = float.MaxValue;
            float maxNoiseHeight = float.MinValue;

            data = new float[properties.sizeBound, properties.sizeBound];
            for (int x = 0; x < properties.sizeBound; x++)
            {
                for (int y = 0; y < properties.sizeBound; y++)
                {
                    float amp         = 1;
                    float freq        = 1;
                    float noiseHeight = 0;

                    for (int octave = 0; octave < octaveOffsets.Length; octave++)
                    {
                        float noiseX = (x - halfWidth + octaveOffsets[octave].x) / properties.scale * freq;
                        float noiseY = (y - halfHeight + octaveOffsets[octave].y) / properties.scale * freq;

                        float noiseValue = (float)(noiseGenerator.Noise2((double)noiseX, (double)noiseY));
                        noiseHeight += noiseValue * amp;

                        amp  *= properties.persistance;
                        freq *= properties.lacunarity;
                    }

                    if (noiseHeight > maxNoiseHeight)
                    {
                        maxNoiseHeight = noiseHeight;
                    }
                    else if (noiseHeight < minNoiseHeight)
                    {
                        minNoiseHeight = noiseHeight;
                    }

                    data[x, y] = noiseHeight;
                }
            }

            switch (properties.normalizeType)
            {
            default:
            case NoiseMapProperties.NormalizeType.GLOBAL:
                Normalize();
                break;

            case NoiseMapProperties.NormalizeType.LOCAL:
                Normalize(minNoiseHeight, maxNoiseHeight);
                break;
            }

            return(data);
        }
Beispiel #3
0
    public static float[,] GenerateFalloffMap(int size, int seed)
    {
        float[,] map = new float[size, size];
        OpenSimplex2F simplexNoise = new OpenSimplex2F(seed);

        for (int i = 0; i < size; ++i)
        {
            for (int j = 0; j < size; ++j)
            {
                float x = i / (float)size * 2 - 1;
                float y = j / (float)size * 2 - 1;

                float value = (float)simplexNoise.Noise2(x, y);
                map[i, j] = value;
            }
        }

        return(map);
    }
Beispiel #4
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            if (widthInputBox.Value != 0 && heightInputBox.Value != 0)
            {
                Random random = new Random();
                heightBitmap = new Bitmap(Convert.ToInt32(widthInputBox.Value), Convert.ToInt32(heightInputBox.Value));
                blendBitmap  = new Bitmap(Convert.ToInt32(widthInputBox.Value), Convert.ToInt32(heightInputBox.Value));

                long seed = useRandomSeedCheckBox.Checked ? random.Next(int.MinValue, int.MaxValue) : Convert.ToInt64(seedInputBox.Value);

                int coordinateMultiplier = 1;

                double finalMax = 1d;
                double value;

                Text = "HeightMapGen - Working...";

                if (useFastLibraryRadioButton.Checked)
                {
                    OpenSimplex2F noiseLibrary = new OpenSimplex2F(seed);

                    for (int x = 0; x < widthInputBox.Value; x++)
                    {
                        for (int y = 0; y < heightInputBox.Value; y++)
                        {
                            value = normalizeValue(noiseLibrary.Noise2(x / Convert.ToDouble(resolutionInputBox.Value), y / Convert.ToDouble(resolutionInputBox.Value)), 1d, -1d, 1d, 0d);

                            for (int o = 1; o - 1 < octavesInputBox.Value; o++)
                            {
                                finalMax += 1d / Math.Pow(2, o);

                                value += 1d / Math.Pow(2, o) * normalizeValue(noiseLibrary.Noise2(Math.Pow(2, o) * (x / Convert.ToDouble(resolutionInputBox.Value)), Math.Pow(2, o) * (y / Convert.ToDouble(resolutionInputBox.Value))), 1d, -1d, 1d, 0d);
                                coordinateMultiplier = coordinateMultiplier * 2;
                            }

                            mapValue(x, y, value, finalMax, Convert.ToDouble(exponentInputBox.Value));
                        }
                    }
                }
                else
                {
                    OpenSimplex2S noiseLibrary = new OpenSimplex2S(seed);

                    for (int x = 0; x < widthInputBox.Value; x++)
                    {
                        for (int y = 0; y < heightInputBox.Value; y++)
                        {
                            value = normalizeValue(noiseLibrary.Noise2(x / Convert.ToDouble(resolutionInputBox.Value), y / Convert.ToDouble(resolutionInputBox.Value)), 1d, -1d, 1d, 0d);

                            for (int o = 1; o - 1 < octavesInputBox.Value; o++)
                            {
                                finalMax += 1d / Math.Pow(2, o);

                                value += 1d / Math.Pow(2, o) * normalizeValue(noiseLibrary.Noise2(Math.Pow(2, o) * (x / Convert.ToDouble(resolutionInputBox.Value)), Math.Pow(2, o) * (y / Convert.ToDouble(resolutionInputBox.Value))), 1d, -1d, 1d, 0d);
                                coordinateMultiplier = coordinateMultiplier * 2;
                            }

                            mapValue(x, y, value, finalMax, Convert.ToDouble(exponentInputBox.Value));
                            finalMax = 1d;
                        }
                    }
                }

                heightMapImageBox.Image = heightBitmap;
                blendMapImageBox.Image  = blendBitmap;

                Text = "HeightMapGen";
            }
        }