- Home /
Why does the default Unity sphere have duplicate vertices?
If I print the length of the default Unity sphere mesh, I get 515 vertices. If I run vertices.Distinct().ToArray(), I get 386 vertices.
From Anatomy of a Mesh:
By calling Mesh.RecalculateNormals, you can get Unity to work out the normals’ directions for you by making some assumptions about the “meaning” of the mesh geometry; it assumes that vertices shared between triangles indicate a smooth surface while doubled-up vertices indicate a crisp edge.
So, if duplicate vertices indicate a crisp edge to the Unity renderer, and a sphere is supposed to be a perfectly smooth object, then why does the default Unity sphere mesh have any duplicate vertices at all? Wouldn't duplicate vertices only hurt the renderer's ability to draw a perfectly smooth sphere?
Answer by Bunny83 · Aug 08, 2019 at 12:02 AM
The answer is simple: UV mapping. The vertex normals are not the only reason why you need to split vertices. Any time two or more faces which meet at a vertex need different vertex attributes at this point it need to be split. That's why most of the vertices of a sphere are actually fully shared. However UV seams will force some duplicates.
In the past Unity had a sphere mesh which is often called a UV sphere. This mesh only had one UV seam and that was one seam from tne north pole to the south pole. Note that the north and south pole were duplicated several times (once for each longitude). At this projection the top edge of the texture would collapse into a single point (the north pole) and the bottom edge of the texture forms the south pole.
Since this projection generally causes a lot of distortion at the poles Unity switched to to a cube sphere. That's essentially 6 subdivided planes of a cube which have been "spherified". The advantage is that you don't get that extreme distortions at the poles. Only minor distortions at the "cube corners". Unity also defines two different unwraps (UV channel 0 and 1) which are unwrapped differently. This probably helps with lightmap projections onto the sphere.
Note that in order to draw a perfectly smooth sphere all you need are equal normals at the duplicated vertices. RecalculateNormals will most likely produce artifacts on Unity's default sphere. The normals are already setup correctly. The normals for a perfect sphere are actually quite easy to calculate. If the mesh origin is the center of the sphere (which is almost always the case) then the local vertex position is the same as the normal vector at this point. You just need to normalize that vector. Of course if you apply some kind of deformations to the sphere so it's not really a sphere anymore, this is not true anymore.