I’m trying to create a procedural heightmap using LibNoise for Unity. It works brilliantly for creating images and textures, however when I apply the heightmap to a Terrain I get something like this:
I’m not entirely sure why this is, but it doesn’t seem to be to do with the texture since it displays at full resolution when I apply the texture to a Plane.
When using TerrainToolkit, however, the terrain appears smooth, meaning that it also shouldn’t be a problem with the terrain settings.
My code for heightmap generation and allocation is as follows:
public void GenerateTerrainMountains () {
RidgedMultifractal mountainTerrain = new RidgedMultifractal();
mountainTerrain.Seed = (int) System.DateTime.Now.Ticks;
mountainTerrain.OctaveCount = 4;
mountainTerrain.Frequency = 1;
mountainTerrain.Quality = QualityMode.High;
ModuleBase mountainModule = mountainTerrain;
TerrainData terrainData = terrain.terrainData;
float[,] heightMapData = terrainData.GetHeights (0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight);
heightMap = new Noise2D (terrainData.heightmapWidth, terrainData.heightmapHeight, mountainModule);
heightMap.GeneratePlanar (0, 1, 0, 1);
Texture2D heightMapTexture = heightMap.GetTexture ();
heightMapTexture.Apply ();
previewPlane.renderer.material.mainTexture = heightMapTexture;
Color[] colours = heightMapTexture.GetPixels ();
// Read all detail layers into a 3D int array
int index = 0;
for (int heightX = 0; heightX < terrainData.heightmapWidth; heightX ++) {
for (int heightY = 0; heightY < terrainData.heightmapHeight; heightY ++) {
float heightMapOffset = colours [index].grayscale;
heightMapData [heightX, heightY] = heightMapOffset;
index ++;
}
}
// Write all detail data to terrain data
terrainData.SetHeights (0, 0, heightMapData);
}
If you need any more information I will be glad to provide it.
Thanks in advance