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
1
Question by Chimera3D · Jan 16, 2014 at 06:54 AM · texturespherecoordinatesprojection

Equirectangular Projection of Sphere onto Texture

Okay so I have a script that generates planets and that all works fine but I want to essentially create a "heightmap" of the surface of the sphere based on the vertex distance from the center minus the planet's radius (sea level). So I managed to get the latitude and longitude of every vertex but for whatever reason when I process these values in the xCord = ... and yCord = ... lines they always end up both equaling zero - no matter what, which I don't understand. Essentially with those two lines all I am doing is converting the latitude and longitude coordinates into x and y pixel coordinates. Part of my code is available below.

EDIT: By the way 72 and 36 are the dimensions of the texture.

EDIT 2: So I tried changing all of the constants in the xCord = ... and yCord = ... lines and now they aren't returning zero, so that was one of the problems and now I'm getting... something. The screenshot below shows the output. What I don't get is why 0,0 is the position of the bottom, left pixel and 72,36 is not the top, right pixel as I thought this was the case.

EDIT 3: I think I resolved a bunch of problems with calculating latitude and longitude and everything seems to be working but I'm still getting undesirable results, without any color changing yet I should get a completely black map, a full map... help? Screens below.

     void MakeMap () {
     
     texture = new Texture2D(72, 36);
     
     vertices = planetVars.vertices;
     
     float xCord = 0;
     float yCord = 0;
     
     for(int i = 0; i < vertices.Length; i++){
         
         Vector3 globalVertPos = planet.transform.TransformPoint(vertices[i]);
         
         Vector3 vectorA;
         vectorA = (globalVertPos - planet.transform.position);
         vectorA.y = 0;
         
         float lng = 0;
         Vector3 refRight= Vector3.Cross(Vector3.up, planet.transform.forward);
         float ang = Vector3.Angle (vectorA, planet.transform.forward);
         float sign = (Vector3.Dot(vectorA, refRight) > 0.0f) ? -1.0f: 1.0f;
         lng = sign * ang;
     
         //print(lng);
         
         float lat = 0;
         lat = Vector3.Angle (vectorA, (globalVertPos - planet.transform.position));
         if(globalVertPos.y < planet.transform.position.y){
             
             lat *= -1;
             
         }
     
         //print(lat);
         
         xCord = (lng + 180f) * (texture.width/360f);
         yCord = ((lat - 90f) * (texture.height/180f));
         
         float dist = Vector3.Distance(globalVertPos, planet.transform.position);
         color = Color.Lerp (white, black, dist);
         
         texture.SetPixel ((int)xCord, (int)yCord, color);
         
     }
     
     texture.Apply();
     
 }

EDIT 2:

alt text

EDIT 3:

alt text

equirectangular project screenshot.png (20.4 kB)
equirectangular projection screenshot 2.png (105.5 kB)
Comment
Add comment · Show 1
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 robertbu · Jan 16, 2014 at 07:22 AM 0
Share

I haven't the time right now to work through you code in detail, but I have one concern based on a quick read. Unless you've converted them, vertices are in local coordinates. If you haven't made the conversion, you are mixing local and world coordinates in your calculation.

Note your calculation might be best done in local coordinates. You avoid some of what you are doing here.

2 Replies

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

Answer by Chimera3D · Jan 17, 2014 at 09:42 AM

Okay, so I finally figured out how to do this, instead of trying to use vertex data I just created a sphere of positions surrounding my planet as a list of Vector3's, then I cast a rays down onto the planet and save the raycast hit positions. Instead of processing vertices in my function above I process the raycast hit points and it works almost flawlessly.

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
0

Answer by syedzainnn · Aug 29, 2016 at 04:57 AM

Can you show the script you're using to save points via raycasting?

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

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

19 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

Related Questions

Equirectangular or radial texture scaling on a sphere 0 Answers

Texturing a icosphere 0 Answers

How to use spherical coordinates in unity? 0 Answers

Draw Plataforms with mouse 1 Answer

Draw some vectors over a sphere, just like latitude and longitudes with the help of 2D texture 0 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