Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by $$anonymous$$ · Apr 11, 2018 at 03:50 PM · meshsphereprocedural generationlibnoise

Generating spherical terrain from a spherical heightmap

Hi all,

I'm using libnoise to generate a spherical heightmap, which is easy enough. However, I'm stuck on mapping this heightmap onto the sphere in order to get a nice terrain going. I'm familiar with the basics, like going through the vertices, using Texture2D.GetPixel(), etc. but actually implementing this is causing me a headache.

There are already several questions about this on the internet but none of them really go in depth about the implementation. I imagine it's not as simple as just looping through the vertices and applying the y-value to it like you do with planes.

I also thought about using regular heightmaps and using a cube-sphere but the implementation beind that confuses me too.
Any help is appreciated!

Comment
Add comment · Show 2
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 BastianUrbach · Apr 11, 2018 at 04:20 PM 0
Share

Can you say more about that heightmap? What kind of layout does it use? Is it just latitude and longitude mapped to U and V texture coordinates? If your terrain is simply a unit sphere mesh then you just need to multiply each vertex with (1 + m * h) where h is the height from the heightmap and m is the maximum height. The main question is how you would sample the texture.

avatar image $$anonymous$$ BastianUrbach · Apr 11, 2018 at 04:39 PM 0
Share

@coeusueoc
These are two examples of the heightmap, the first picture is how it looks flat, second is how it looks on a sphere. https://imgur.com/a/RVyxD And yes it's simply a unit sphere.

1 Reply

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

Answer by BastianUrbach · Apr 11, 2018 at 05:00 PM

Seems like you just need to calculate latitude and longitude for each vertex, then sample your texture with those values, then translate the vertices outwards depending on the value.

float latitude = Vector3.Angle(Vector3.up, vertex);
float longitude = Vector3.SignedAngle(Vector3.right, vertex, Vector3.up);
float height = texture.GetPixelBilinear(latitude / 180, longitude / 360).r;
vertex *= 1 + maxHeight * height;
Comment
Add comment · Show 4 · 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 $$anonymous$$ · Apr 12, 2018 at 03:20 AM 0
Share

Hey, this seems to be working good so far, however, it seems that it only changes the vertices on roughly have of the shape.
https://i.imgur.com/JZRdVr1.png

avatar image BastianUrbach $$anonymous$$ · Apr 12, 2018 at 07:30 AM 0
Share

Set "wrap mode" to "repeat" in the texture import settings or add the line

longitude = (longitude + 360) % 360;
That should fix it.
avatar image BastianUrbach BastianUrbach · Apr 12, 2018 at 07:34 AM 0
Share

Oh wait no, I think the problem is that latitude and longitude are the wrong way round. Use

GetPixelBilinear(longitude / 360, latitude / 180)
ins$$anonymous$$d.
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

87 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UV-ing a sphere procedurally 1 Answer

How to create a spherical navigation? 1 Answer

Mesh collider trigger 2 Answers

Setting triangles failing 0 Answers

How do I guarantee a generated sphere's mesh is facing outward? 1 Answer


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