Do I have to use shared vertices in mesh in Unity?

2019-02-20 23:21发布

问题:

I want to create procedurally generated landscape meshes with a flat shaded look in Unity3D.

I thought it would be the best to create three unique vertices per triangle and use one calculated normal for the vertices. Building this mesh would lead to redundant vertex position information. (Would it have an impact on render time?)

Anyway... the problem is that I would like to use shading techniques e.g. ambient occlusion on this mesh. I don't want to mess up the mesh topology that Unity3D expects for its shaders.

Is it better to create the meshwith shared vertices, add perhaps a custom vertex attribute e.g. 'flat_normal' and customize the shaders to use this?

回答1:

The simple answer is

No,

Unity does not, in the slightest, "look for" shared verts. No 3D pipeline has anything to do with shared verts. Shared verts does not help or hinder the 3D pipeline in anyway at all.

(Very often, when for example we are making dynamic mesh, we just "never use shared verts at all" because, as you have probably found, it's often far simpler to not use shared verts.)

The one and only reason to use shared verts is if, for some reason, it happens to make it more convenient for you. In that case the 3D pipeline (Unity or elsewhere) "allows" shared verts, with no downside.



回答2:

There might be 2 considerations for using shared vertices:

  • To reduce memory usage. (Only slightly, but if you need less UV1's, UV2's, normals, vertices it can add up)
  • to make it more convenient to share normals. (You only have to alter one normal of a vertex if you want to keep the surface smooth. )

These are no big reasons, but as most of the meshes from other 3D programs that you encounter, it's probably best to get used to shared vertices.