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
0
Question by OverGast · Nov 01, 2020 at 07:59 PM · unity 5texture

Convert texture coordinates into a polar version?

Hi there!

So basically, as the title says, I'm trying to convert the texture coordinates into a polar/spherical texture. However I dont manage to get it to work (tried many things out there like:
https://stackoverflow.com/questions/58910317/is-it-accurate-to-convert-latitude-and-longitude-into-3d-coordinate-on-sphere https://stackoverflow.com/questions/25932175/glsl-es-mapping-texture-from-rectangular-to-polar-coordinates-with-repeating and many more things)
I know this is achievable since LibNoise has its own version implemented (I also tried to adjust it but doesnt work either). Let me show you an example texture: https://ibb.co/KVFHKJj

You can see the effect Im trying to get in the poles, where the texture gets distorted the closer you are to the poles. What I'd like is to get that same effect when setting/creating a new texture from script, but I cant manage to get it no matter how hard I try....

To further understand, I must explain a little more: I have a texture created from script (that is mapped in a sphere/planet) so when the user clicks on it, a new city is created (that basically, change the pixels colors around the click position so it looks like a city):
https://ibb.co/T0d2YWk
The problem is if you click near the poles, the pixels are weirdly place, like this: https://ibb.co/GRgyFqk

And this is the code so far, if anyone can help or know anyway to accomplish this I will highly appreciate it. Thanks! //Simply get a the clicked point and draw a ray + create a temporal texture
var ray = Camera.main.ScreenPointToRay(Input.mousePosition); Renderer renderer = hit.transform.GetComponent(); MeshCollider meshCollider = hit.collider as MeshCollider; Material thisMat = renderer.material; Texture2D heightMap = renderer.material.GetTexture("_HeightMap") as Texture2D; Texture2D tempTex = new Texture2D(nightTex.width, nightTex.height); Graphics.CopyTexture(thisMat.GetTexture("_Lights") as Texture2D, tempTex);

             int thisCitySeed = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
             UnityEngine.Random.InitState(thisCitySeed);
     
             Vector2 pixelCenter = hit.textureCoord;
     
             pixelCenter.x *= nightTex.width;
             pixelCenter.y *= nightTex.height;
             int ringsPerCity = UnityEngine.Random.Range(10, 150);
 
             //This FOR loop is basically for the city shape and such stuff
 //Also, I suppose here is where I would calculate the polar coordinate of each calculate pixel so I can move it to the proper place, but i dont know how
             for (int i = 0; i < ringsPerCity; i++)
             {
                 float cityRadius = 0f + (i / 2f);
                 float lightsAngle = UnityEngine.Random.Range(1f, 10f);
                 int maxLoop = lightsAngle >= 6f ? 100 : 80;
                 int loop = i == 0 ? maxLoop - 100 : maxLoop / i;
     
                 for (int j = 0; j < loop; j++)
                 {
                     var offset = new Vector2(Mathf.Sin(lightsAngle), Mathf.Cos(lightsAngle)) * cityRadius;
   
                     tempTex.SetPixel((int)pixelCenter.x + (int)offset.x, (int)pixelCenter.y + (int)offset.y, Color.white);
                     lightsAngle++;
                 }
             }
     
             tempTex.Apply();

If is needed any more information please ask! And please note that this is not an end version of the script, its only for testing purposes, once I get it working I will change it so the code is clearer!

**EDIT: Please, this is effect I am looking for: https://graphicdesign.stackexchange.com/questions/111391/how-can-i-distort-an-image-to-wrap-around-a-sphere-with-no-pinching**

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

.tex to assetbundle 0 Answers

Unity 5 upside down texture on 1 side of cube 1 Answer

Shader Forge can't work in Unity2017 0 Answers

Fps drops after entering house 0 Answers

Assigning UV Map to model at runtime 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