- Home /
Why does assigning heightmapResolution increase the size of my terrain?
So I've been trying to generate a terrain using code and I've come across a lot of problems. The most recent one is the fact that when I assign heightmapResolution the size of my terrain increases by a factor of some power of two.
For example, if my heightmapResolution is 513, then my terrain size increases by a factor of 16. If my heightmapResolution is 257, then my terrain size increases by a factor of 8.
I must stress that the size increase happens only in X and Z axis. Height remains unchanged.
Debug.Log (terrainData.size);
terrainData.heightmapResolution = heightmapResolution;
Debug.Log(terrainData.size);
The change is already visible in the second Debug.Log.
Any ideas as to why?
Answer by Pizmovc · Apr 19, 2015 at 03:05 PM
I figured it out.
I had to set the heightmap resolution before I set the terrain size. Here is the final code that works as intended.
terrainData.heightmapResolution = heightmapResolution;
terrainData.size = new Vector3(width, height - sandBaseHeight, length);
terrainData.baseMapResolution = baseMapResolution;
terrainData.SetDetailResolution((int)detailResolution.x, (int)detailResolution.y);
terrainData.alphamapResolution = aplhaMapResolution;
Debug.Log ("Terrain size: " + terrainData.size); //Correct terrain size
Hope this helps someone else!
Answer by siaran · Apr 17, 2015 at 11:58 PM
This is a bit simplified and it's late so I may be wrong, but:
Terrain is built off of a height map. The resolution of this heightmap is the size of this map. Increasing the resolution of the heightmap therefore also increases the size of the terrain, unless you change the...well, the distance in worldspace between heightmap samples, basically. Not sure what variable that is, though.
So is there some $$anonymous$$imal distance between two vertexes? Because I see no other explanation for the increased terrain size. The resolution of the heightmap should just affect how small of an area you can assign different height to, no? It should basically just give you finer control over height.
That is at least how I understand it. I may be completely wrong :)
There really should be better documentation for terrain. There are just one sentence descriptions for various variables and functions. Not much to go on.
There should be some variable that gives you a denser sampling that'd decrease your terrain size yes, but idk which one that would be or if it's even accesible. Like you said the documentation on terrain isn't great. Try experimenting with the accesible varialbes I guess?