Math illiterate Game dev/programming/unity noob here. Could someone please explain this to me with words and pictures? I’ve read explanations online and off but still cannot seem to grasp. Thx beforehand
When you have a specific requirement like this, it’s usually due to an algorithm used by the game engine. In this case, most likely Unity is breaking the terrain up into chunks, and more likely into a Quadtree or Octree. I actually just posted on the concept of these here:
But the underlying key is that a quadtree requires a single quad to be sub-divided into 4 new quads. Thus, you must have a vertex in the center. If you had a 2x2 image (for simplicity), there’s no vertex in the center:
.----.
------
------
.----.
But with a 3x3, you get a vertex in the center:
.----.----.
-----------
-----------
.----.----.
-----------
-----------
.----.----.
As you can see by my awesome ascii (or awesome UTF-16) clip art
there are 4 identifiable quads here.
Note this MAY not be the reason for the requirement, but I can’t think of any others, and it is common for engines that use these trees to require this.
EDIT: I read @Tryz answer after I posted this, and he brings up a good point I actually meant to mention. You want each vertex to line up with a pixel in the heightmap image. Otherwise, you would get aliasing effects in your terrain, because Unity would still require a power of 2 + 1 number of verts to support the tree, but it would have to interpolate between pixel values in the heightmap if they didn’t line up with verts, and it would even have to guess at what nearest power of 2 size you wanted your terrain to be. Instead, they just mandate it.
Hey,
I’m a little late, but the reason is that a mesh is created from the pixels in the image.
The pixels of the image than pair to the vertices of the mesh and the vertices height are determined by the pixels’ color.
So if you have a height map of 3 x 3, you get this:
+---+---+
| | |
+---+---+
| | |
+---+---+
The “plus one” is used to ensure the pixel values of the height map line up nicely to the vertices.
Imagine you have a height map of 1 x 1 (no plus one), you can’t turn that into a mesh. However, a height map of 2 x 2 == (1 plus one) x (1 plus one) works:
+---+
| |
+---+
Hope that helps.