- Home /
UV Mapping - by vertex or face? Weird banding
Hi, I have looked around quite a bit and understand the the [0..1] range for UV maps. However, I have read in different places the number of UVs to be assigned to a mesh - in some cases, it seems to be by the number of vertices, in other cases by the number of faces * 3 (in the case of shared vertices).
I ask because I've tried the following to UV map a sphere (I'd like it to look as it it does in the preview window on the lower right) using this wikipedia code:
for (int i = 0; i < vertices.Count; i++) {
Vector3 dir = Vector3.Normalize(Vector3.zero - vertices[i]);
uvs.Add(new Vector2((0.5f + Mathf.Atan2(dir.z, dir.x)) / (2 * Mathf.PI), (0.5f - Mathf.ASin(dir.y)) / (Mathf.PI)));
}
When I set the mesh UVs to be that list I create, that shows:
However, if I try to do it by face (adding a uv record for each vertex in each face, even if shared) I don't get anything at all. Thoughts?
Well it's definitely by vertex - now as to the banding, I'm having a bad head day and can't quite figure out if the mapping function you are using is creating artefacts near the 1 point. It looks to me like something is returning a value of 1 or 0 at the start and end of the seam. Float inaccuracy? Something wrong with the function? Haven't got the brain power this morning to tell you I'm afraid :S
Answer by Bunny83 · Sep 18, 2013 at 06:09 AM
I can't test it, but I would say this:
(0.5f + Mathf.Atan2(dir.z, dir.x)) / (2 * Mathf.PI)
Should be:
(0.5f + Mathf.Atan2(dir.z, dir.x) / (2 * Mathf.PI))
You also divide the 0.5 by 2PI which doesn't make much sense.
edit
The same for the second value. Take another look at the wiki formula
Answer by DarkPixel · Oct 06, 2013 at 02:47 PM
Here's a good article that explain the possible problems (and how to solve them) with sphere UVs
Your answer
Follow this Question
Related Questions
Shared vertices or vertices for each face? 0 Answers
How to get to know a mesh' faces normals? 0 Answers
Select a face of an object ingame 3 Answers
Vertex animation or uv animation ? which one is more efficient? 1 Answer
How can I convert the texture coordinates of the multi-spite to 0-1? 0 Answers