- Home /
UV mapping icosphere
I'm creating an Icosphere with a script, it generates the sphere perfectly but i'm having trouble UV mapping it. Using this code for the mapping
Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < mesh.vertices.Length; i++) { uvs [i] = new Vector2 ((Mathf.Atan2 (mesh.vertices [i].z, mesh.vertices [i].x) / Mathf.PI / 2), (Mathf.Acos (mesh.vertices [i].y / radius) / Mathf.PI)); }
I'm not sure whats happening and how to fix it. I've tried googling it and from what i can find, it looks like i'm not using the full range of the UV array, as in after the code above is run each value of UV vector2 array is between 0.0 and 0.9. even if that makes sense i'm still not sure how to fix it. Any help is appreciated.
Answer by Bunny83 · Apr 28, 2016 at 06:34 AM
Well, what you see here is he usual UV-seam you'll always have when mapping a whole sphere onto a single texture. You most likely have a full-shared sphere here, so you don't have any vertex duplicated.
That means the right edge of that "blurry" strip is simply the left end of your texture and the left edge is the right end of the texture after you went around the sphere counter clockwise. The strip between is again the whole texture but in reverse since the "U" coordinates of the right edge is "0" but is "1" for the left edge.
You have two options:
Create a UV seam by duplicating the vertices at the seam so you can map one vertex for the right side and one for the left.
Map only half the sphere to the texture and mirror the texture onto the second half. This of course doesn't work if you want to use a specific texture that must not be mirrored or duplicated. However this solution doesn't require a UV seam in the vertex data.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075746im_/https://answers.unity.com/themes/thub/images/avi.jpg)