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][1]:

			for (int i = 0; i < vertices.Count; i++) {
				Vector3 dir = Vector3.Normalize(Vector3.zero - vertices*);*

_ 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?
[1]: UV mapping - Wikipedia

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.


The same for the second value. Take another look at the wiki formula

Here’s a good article that explain the possible problems (and how to solve them) with sphere UVs

Sphere Mesh Generation