Playing with some Documentation about Perlin Noise I managed to create this map:
Nothing different from other Procedural Generated Maps. It is a HeightMap with colours at given heights.
The problem I am having with it is that this Colour Map it's in a single plane.
QUESTION
¿How can I draw the Perlin Noise Map in a plane made by a set of individual tiles?
The idea behind that question is that each tile will have a set of values such as population, water levels, soil quality, temperature and etc. I want to store things which can not be done on a simple single plane (according to my knowledge in this matter).
EDIT: Ok, after some more planning and research in the matter I did the next thing:
I have created a new class type named MapData.cs, this class will hold information about the heights, temperature, wetness and etc form the map as show below
MapData class
public class MapData{
//The MapData class will hold different types of Data
//Temperature, Rainfall, etc.
public float[,] Data;
public float Min { get; set; }
public float Max { get; set; }
public MapData(int width, int height)
{
Data = new float[width, height];
Min = float.MinValue;
Max = float.MaxValue;
}
}
Then i will use that MapData class to put data into the tiles as show below:
Load Tiles function inside the Generator Class
void LoadTiles()
{
for (int x = 0; x < mapWidth; x++)
{
for (int y = 0; y < mapHeight; y++)
{
Tiles t = new Tiles();
t.X = x;
t.Y = y;
float heightValue = HeightData.Data[x, y];
heightValue = (heightValue - HeightData.Min) / (HeightData.Max - HeightData.Min);
t.HeightValue = heightValue;
if (heightValue < DeepWater)
{
t.HeightValue = DeepWater;
}
else if (heightValue < ShallowWater)
{
t.HeightValue = ShallowWater;
}
else if (heightValue < Sand)
{
t.HeightValue = Sand;
}
else if (heightValue < Grass)
{
t.HeightValue = Grass;
}
else if (heightValue < Forest)
{
t.HeightValue = Forest;
}
else if (heightValue < Mountain)
{
t.HeightValue = Mountain;
}
else { t.HeightValue = Snow; }
}
}
My actual problem here is that i am still confused with the Texture Generator as how do i apply this new concept into it. I am still learning and I do not want to mess up my progress.
Texture Generator
public class TextureGenerator{
//Height Colours
private static Color DeepColor = new Color(15 / 255f, 30 / 255f, 80 / 255f, 1);
private static Color ShallowColor = new Color(15 / 255f, 40 / 255f, 90 / 255f, 1);
private static Color RiverColor = new Color(30 / 255f, 120 / 255f, 200 / 255f, 1);
private static Color SandColor = new Color(198 / 255f, 190 / 255f, 31 / 255f, 1);
private static Color GrassColor = new Color(50 / 255f, 220 / 255f, 20 / 255f, 1);
private static Color ForestColor = new Color(16 / 255f, 160 / 255f, 0, 1);
private static Color RockColor = new Color(0.5f, 0.5f, 0.5f, 1);
private static Color SnowColor = new Color(1, 1, 1, 1);
//This class will receive the colorMap array we set up before along with width and height
public static Texture2D TextureFromColourMap(Color[] colourMap, int width, int height)
{
//New texture object and apply that color code.
Texture2D texture = new Texture2D(width, height);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.SetPixels(colourMap);
texture.Apply();
return texture;
}
public static Texture2D TextureFromHeightMap (float[,] heightMap)
{
int width = heightMap.GetLength(0);//Grab the x from the heightMap array
int height = heightMap.GetLength(1);//Grabt the y from the heightMap array
Texture2D texture = new Texture2D(width, height);//New texture object
Color[] colourMap = new Color[width * height];//New colourMap object
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
//Gray scale colours for the NoiseMap
colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);//Explained before in Noise Script
}
}
return TextureFromColourMap(colourMap, width, height);//Using the gray scale, coloursMap has colours in it!
}
}
I had inside the texture Generator some colour code for my initial tests for coloring the Perlin Noise over a plane. As you can see up in the image.
MapPixel[x,y] = GenerateTerrainColourAt(x,y)
, can't you use effectively the same principles to setTile[x,y].population = GeneratePopulationAt(x,y)
orPopulationTiles[x,y] = ...
? I'm trying to identify what specific kind of help you need moving from the generation you've done so far to your tile-based approach. \$\endgroup\$