Unity Terrain In-Depth

All About Heightmaps

When you sculpt on the Unity Terrain, that sculpt data is written to a heightmap. A heightmap is a texture whose pixels represent the height of a vertex point on the terrain.

A white pixel in the texture would mean the vertex would be at the maximum altutude. Black would be 0. Shades of grey would be values in between.

This heightmap resolution value in terrain settings corresponds to the squareroot of maximum vertex count of the sculpted terrain when it’s closest to the camera. That might raise your eyebrow, but if we set the heightmap resolution to its lowest, which is 33, then sculpted something all over, and if you counted the vertices across the terrain, you’d get 33.

Detail vs. Performance

An easy way to do determine what is amount of detail is best for you is to start by making your terrain values similar to the resolution values. Set the width, height, and resolution to 33. Remember, heightmap resolution is a power of two + 1. Since they are 1 to 1, that means after sculpting some detail there is right now 1 pixel of heightmap for every meter of terrain. So there is 1 vertex per meter.   Is that enough? That’s up to you. As an artist, I like to really sculpt my terrain so I’ll double or even quadruple that resolution.  The terrain is small so it won’t be a big issue on performance if I jack up the resolution. With the resolution 4x that of the size, I know I have a vertex every quarter meter. But, if you’re doing Mobile or VR terrain, you’ll have to be more picky with the detail as a high vertex count will affect your framerate.

Pay Attention!

In my opinion, this is the most important concept to understand with unity terrains. The amount of detail is governed by that heightmap resolution value. You definitely want to balance the heightmap resolution vs the terrain width and height. Otherwise, you’ll render far too many triangles than what you need.