Example #1
0
    private Texture2D GenerateTexture(float[,] noiseMap)
    {
        int width  = noiseMap.GetLength(0);
        int height = noiseMap.GetLength(1);

        Vector2 center = new Vector2(width * 0.5f, height * 0.5f);

        float[,] gradientMap = RadialGradient.GenerateGradient(mapValues.width, mapValues.height, mapValues.gradientThreshold, center, mapValues.gradientIntensityPoint, mapValues.gradientIntensity);

        Texture2D texture = new Texture2D(width, height);

        Color[] colorMap = new Color[width * height];

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                colorMap[y * width + x] = Color.Lerp(Color.black, Color.white, noiseMap[x, y] + gradientMap[x, y]);
            }
        }

        texture.SetPixels(colorMap);
        texture.Apply();
        return(texture);
    }
Example #2
0
    private void LoadMapValues()
    {
        heightMap = Noise.GenerateNoise(mapValues.width, mapValues.height, mapValues.seed, mapValues.offsetX, mapValues.offsetY, mapValues.scale, mapValues.octaves, mapValues.persistance, mapValues.lacunarity);

        Vector2 center = new Vector2(mapValues.width * 0.5f, mapValues.height * 0.5f);

        gradientMap = RadialGradient.GenerateGradient(mapValues.width, mapValues.height, mapValues.gradientThreshold, center, mapValues.gradientIntensityPoint, mapValues.gradientIntensity);

        for (int x = 0; x < mapValues.width; ++x)
        {
            for (int y = 0; y < mapValues.height; ++y)
            {
                float xPos = x;
                float yPos = y;

                tilemapPositionValues.Add(new Vector2(xPos, yPos), Mathf.Clamp01(heightMap[x, y] + gradientMap[x, y]));
            }
        }
    }
Example #3
0
    private void GenerateMap()
    {
        heightMap = Noise.GenerateNoise(mapValues.width, mapValues.height, mapValues.seed, heightMapValues.offsetX, heightMapValues.offsetY, mapValues.scale, heightMapValues.octaves, heightMapValues.persistance, heightMapValues.lacunarity);

        Vector2 center = new Vector2(mapValues.width * 0.5f, mapValues.height * 0.5f);

        float[,] gradientMap = RadialGradient.GenerateGradient(mapValues.width, mapValues.height, gradientMapValues.gradientThreshold, center, gradientMapValues.gradientIntensityPoint, gradientMapValues.gradientIntensity);

        for (int x = 0; x < mapValues.width; ++x)
        {
            for (int y = 0; y < mapValues.height; ++y)
            {
                BiomePreset biome = GetBiome(Mathf.Clamp01(heightMap[x, y] + gradientMap[x, y]));

                tilemap.SetTile(new Vector3Int(x, y, 0), biome.PickRandomTile());

                //tilemap.SetTile(new Vector3Int(x, y, 0), SpawnFoliage(biome));
            }
        }
    }
    private Texture2D GenerateTexture()
    {
        Texture2D mask = new Texture2D(texWidth, texHeight);

        Vector2 center = new Vector2(texWidth * 0.5f, texHeight * 0.5f);

        float[,] gradient = RadialGradient.GenerateGradient(texWidth, texHeight, mapValues.gradientThreshold, center, mapValues.gradientIntensityPoint, mapValues.gradientIntensity);

        for (int y = 0; y < texWidth; ++y)
        {
            for (int x = 0; x < texHeight; ++x)
            {
                Color color = new Color(gradient[x, y], gradient[x, y], gradient[x, y], 1);
                mask.SetPixel(x, y, color);
            }
        }
        mask.Apply();

        return(mask);
    }