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 Ozy666 · Jul 23, 2014 at 11:04 PM · shadertexturesphere

How do I fix texture seam from UV spherical mapping?

So, I'm mapping an earth texture to an Icosphere, and ran into the standard issue of the vertices of triangles on the texture boundary spanning and interpolating the entire texture causing a big ugly seam.

I fixed this with the standard fragment shader solution:

             float4 frag(v2f i) : COLOR {
                 float3 tc = i.tex;
                 float3 norm;
                 float3 p;
                 p.x = i.pass_xy_position.x;
                 p.y = i.pass_xy_position.y;
                 p.z = i.pass_xy_position.z;
                 norm.x = sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
                 tc.x = (PI + atan2(p.z, p.x)) / (2 * PI);
                 tc.y = (PI / 2 + asin(p.y / norm.x)) / PI;
                 float4 color = tex2D(decal, tc);
                 return color;
             }

but I'm still left with a single pixel-wide seam at the texture longitude boundary, and some small distortions around the poles. I've tried a couple of different textures from the NASA Blue Earth site, and see the same issue. Any help would be greatly appreciated. alt text

earth_seam.jpg (231.1 kB)
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

Answer by Xeqtion3r · Nov 25, 2015 at 09:18 AM

http://answers.unity3d.com/questions/755222/how-do-i-fix-texture-seam-from-uv-spherical-mappin.html

I know its kinda late but hopefully it will help someone

Comment
Add comment · Show 3 · 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 Ozy666 · Nov 27, 2015 at 03:07 AM 0
Share

I didn't see a solution to the question. Do you have a way to fix this? I'm still interested in an answer. Thanks.

avatar image Xeqtion3r · Nov 27, 2015 at 04:49 AM 0
Share

The seam is caused by incorrect mipmapping. The jump form 0-1 uv corodinates is seen as a big leap and sets the mipmap level to a one that is higher than required Here is a shader i fashioned that will create a spherical map. I suggest using a octahedron sphere to prevent UV visual distortion

 "
 Shader "Unlit/Spherical$$anonymous$$ap
 {
     Properties
     {
         _$$anonymous$$ainTex ("Texture", 2D) = "white" {}
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 100
 
         Pass
         {
         
             CGPROGRA$$anonymous$$
             #pragma vertex vert
             #pragma fragment frag
             // make fog work
             #pragma multi_compile_fog
             
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
                 float3 normal : NOR$$anonymous$$AL;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
                 float4 vertex : SV_POSITION;
                  float3    normal : TEXCOORD1;
             };
 
             sampler2D _$$anonymous$$ainTex;
             float4 _$$anonymous$$ainTex_ST;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
                 o.uv = TRANSFOR$$anonymous$$_TEX(v.uv, _$$anonymous$$ainTex);
                 o.normal = v.normal;
                 UNITY_TRANSFER_FOG(o,o.vertex);
             
                 return o;
             }
             
              #define PI 3.141592653589793
  
             inline float2 RadialCoords(float3 a_coords)
             {
                 float3 a_coords_n = normalize(a_coords);
                 float lon = atan2(a_coords_n.z, a_coords_n.x);
                 float lat = acos(a_coords_n.y);
                 float2 sphereCoords = float2(lon, lat) * (1.0 / PI);
                 return float2(sphereCoords.x * 0.5 + 0.5, 1 - sphereCoords.y);
                 
             }
 
             float4 frag(v2f IN, out float depth:DEPTH) : COLOR
             {
                 float2 equiUV = RadialCoords(IN.normal);
                  depth = 0;
                  equiUV.x = 1- equiUV.x;
                 return tex2Dlod (_$$anonymous$$ainTex, float4(equiUV.x,equiUV.y,0,0));
                
             }
 
             ENDCG
         }
     }
 }
 
avatar image nurrohmawanto · May 19, 2016 at 08:36 AM 0
Share

its work to me in play mode but when I compile to android platform my texture just purple can you help me to fix this problem? I'm beginer in unity

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Equirectangular or radial texture scaling on a sphere 0 Answers

Why does spec map turn object black? 0 Answers

Projecting a plane onto a sphere 2 Answers

There is an issue with texture wrapping around sphere's in unity 0 Answers

How to avoid "cross" pattern in texture when using Bilinear filtering 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