- Home /
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.
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
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.
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
}
}
}
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
Follow this Question
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