Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by InsurgoInsurgisInsurrectum · Nov 23, 2013 at 12:15 PM · heightmaps

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image supernat · Mar 28, 2014 at 06:19 PM 0
Share

I like your awesome ascii art better. :)

avatar image jdk1-0 · Jul 27, 2016 at 09:29 PM 0
Share

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. :-)

avatar image Bunny83 jdk1-0 · Jul 27, 2016 at 11:04 PM 0
Share

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.

avatar image jdk1-0 Bunny83 · Jul 29, 2016 at 03:56 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges