- Home /
Why are heightmap resolutions power of 2 plus one?
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
Answer by supernat · Mar 28, 2014 at 06:16 PM
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: http://answers.unity3d.com/questions/673363/how-to-make-trees-respond-to-a-hit.html
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.
Answer by Tryz · Mar 28, 2014 at 06:10 PM
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.
If this was true, then wouldn't the $$anonymous$$imum just be 2x2 without the recommendation of "should be a power of two plus one?" In addition, a 2x2 is not a power of two plus one, so that example goes against Unity's recommendation, does it not? I think the other answer is probably closer to the actual reason since it explains why the power of two comes into play. A power of two ensures that the surface can be subdivided all the way down, and plus one for the center vertex. But your ASCII art is spot on. :-)
Actually 2x2 is a "power of two plus one" It's "2^0 + 1". He's also right about the reason for the "+1". For whatever quad-count you want you need always +1 vertices. So a "AxA" quad grid needs (A+1)x(A+1) vertices.
Of course he doesn't address the reason why the quad count should be a power of two so i agree that @supernat's answer is more complete.
Since the OP hasn't been online since 2014 i'll accept supernat's answer for now.
Haha, good call. All those math classes and what do I have to show for it... ;-)
But the pixels can still line up to the vertices without the plus one. The pixels would just be on the vertices at that point, ins$$anonymous$$d on the faces if that makes sense. I think the answer might only have to do with subdividing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122544im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Customizable Textures 0 Answers
Raw File / Heightmap Switch at Runtime 1 Answer
Animating Heightmaps in Tessellation Shaders? 1 Answer
Why is my terrain so bumpy when I use heightmaps? 1 Answer
Heightmap is spiky, unsolvable for me 3 Answers