Hey guys!
Im quite new to procedural level generation and worked on a small island generator with different biomes, ressources etc.
I managed to generate different textures and generate a triangulated mesh from it and applied the texutre.
The problem im facing in the moment are some texturing problems. I want the sides of the hills to be grey, but with my method the sides of the walls are always the same color as the floor beneath it.
My english is not the best, so I added a picture.
vertices = new Vector3[(baseMapTexture.width + 1) * (baseMapTexture.height + 1)];
triangles = new int[baseMapTexture.width * baseMapTexture.height * 6];
uvs = new Vector2[vertices.Length];
terrainMesh = new Mesh();
terrainMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
GameObject terrain = Instantiate(new GameObject());
terrain.name = "Terrain";
MeshFilter mf = terrain.AddComponent<MeshFilter>();
MeshRenderer mr = terrain.AddComponent<MeshRenderer>();
terrainMaterial = new Material(Shader.Find("Standard"));
terrainMaterial.mainTexture = ironCoalBaseBiomeMapColorTexture;
terrainMaterial.mainTexture.filterMode = FilterMode.Point;
terrainMaterial.SetFloat("_Glossiness", 0);
mr.sharedMaterial = terrainMaterial;
// Generate vertices
int index = 0;
for (int x = 0; x <= baseMapTexture.width; x++)
{
for (int y = 0; y <= baseMapTexture.height; y++)
{
var height = 0;
if (x < baseMapTexture.width && y < baseMapTexture.height)
{
if (baseMap[x, y] == 0f)
{
height = 0;
}
else if (baseMap[x, y] == 0.1f)
{
height = 2;
}
else if (baseMap[x, y] == 0.15f || baseMap[x, y] == 0.4f)
{
height = 3;
}
else if (baseMap[x, y] == 1f)
{
height = 5;
}
}
vertices[index] = new Vector3(y, height, x);
index++;
}
}
// Generate triangles
int vert = 0;
int tris = 0;
for (int x = 0; x < baseMapTexture.width; x++)
{
for (int y = 0; y < baseMapTexture.height; y++)
{
triangles[tris + 0] = vert + 0;
triangles[tris + 1] = vert + baseMapTexture.width + 1;
triangles[tris + 2] = vert + 1;
triangles[tris + 3] = vert + 1;
triangles[tris + 4] = vert + baseMapTexture.width + 1;
triangles[tris + 5] = vert + baseMapTexture.width + 2;
vert++;
tris += 6;
}
vert++;
}
// Generate uvs
index = 0;
for (int x = 0; x <= baseMapTexture.width; x++)
{
for (int y = 0; y <= baseMapTexture.height; y++)
{
uvs[index] = new Vector2((float)x / baseMapTexture.width, (float)y / baseMapTexture.height);
index++;
}
}
// Apply
terrainMesh.vertices = vertices;
terrainMesh.triangles = triangles;
terrainMesh.uv = uvs;
mf.sharedMesh = terrainMesh;
Hope you guys can point me in the right direction!
Kind regards:
Max