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 TheMasonX · Aug 17, 2015 at 08:10 PM · shaderproceduralsphereuv

SOLVED: Calculate sphere UV from position (without discontinuity)

SOLVED: Read my post below for the solution. It was a simple mip mapping issue (caused by the discontinuity, but not where I expected to find the issue).

I need to calculate the UV coordinates from the world position, which I use to sample a temperature map texture to add snow to the terrain. I used the Atan2 formula described multiple places, including Wikipedia, but the discontinuity along the -x axis (approaches pi from one side an -pi from the other) leads to a pixel wide error region. Error region

Here is the shader code:

 float2 UV = float2( saturate(((atan2(position.z, position.x) / pi) + 1.0) / 2.0), (0.5-(asin(position.y)/pi)) );

And here is the C# version used elsewhere (including calculating the mesh.uv):

 Vector3 d = position.normalized;
 float u = Mathf.Clamp01((Mathf.Atan2(d.z, d.x) / (Mathf.PI) + 1f) * .5f);
 float v = 0.5f - Mathf.Asin(d.y) / Mathf.PI;

I can't use the mesh UV, as it's used for both the terrain and objects. I realize that this is caused by the UV.x wrapping around from 1 back to 0, but as the texture wraps perfectly, forcing it to sample UV.x = 1 on one side and UV.x = 0 on the other side should still smoothly wrap. Any ideas on how to get around this discontinuity?

Here's a sample shader using this UV for anyone to play with and test. I made it in ShaderForge, but I can write up a non-SF example too. Position To UV Shader (Dropbox)

Planet pictured here for reference: Not really necessary for the problem, but it gives a better idea of what I'm using it for

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

1 Reply

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

Answer by TheMasonX · Aug 18, 2015 at 11:14 AM

SOLVED: Joachim Holmer, the creator of Shader Forge, was kind enough to look into this for me, and found out that it was due to the GPU not being able to figure out what mip level to use along the seam. The solution to this is to manually set the mip level using tex2Dlod(), like this: tex2Dlod(_TemperatureMap,float4(TRANSFORM_TEX(UV, _TemperatureMap),0.0,mipLevel))

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

UV-ing a sphere procedurally 1 Answer

How do I go about texturing a flat-shaded generated mesh? 1 Answer

Water on a non-planar mesh 0 Answers

UV offset in surface shader. 1 Answer

Sphere appears to elongate further away I get 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