Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Vertex count in frame debugger question

Discussion in 'General Graphics' started by BakeMyCake, Jan 30, 2019.

  1. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    I'm curious why Unity displays a larger than expected number of vertices for models in the frame debugger.
    Place a default cube in a scene and inspect it in the frame debugger it will show that the model is 24 vertices and 36 indices.
    The index count makes sense, but why is vertex count not 8? I've determined that it's because each vertex acts as part of 3 faces, but what is the technical reason why Unity has to duplicate the same vertex? Is it related to passing different attributes for each face?
     
  2. vthera_joels

    vthera_joels

    Joined:
    Nov 8, 2018
    Posts:
    8
    This is common across all game engines. Things like hard edges and UV splits cause the vertices to double under the hood. So while your cube is authored with only 8 vertices, it is actually drawn with 24 to support hard edge smoothing.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
  4. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    Thanks for the explanations. In case anyone else stumbles onto this here are my observations:

    If you make a model without UVs and import it into Unity with normals disabled the vertex count will match that of the modelling software. Both normals and UVs affect vertex count unfortunately.

    I suspect that it is still possible to have UVs and normals in your mesh without duplicating vertices if you don't need hard edges and UV splitting, but to do that you'd have to either handle importing meshes yourself or tinker with the imported meshes to strip away smoothness groups and rearrange the UVs.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    The short version is any discontinuities require unique vertices.
    A cube with no or smooth normals and a single plane projected UV will only have 8 vertices, but that's not terribly useful.
    The same cube with two UV islands (have 2 sets of three faces in strips) will have 16 vertices.
    Unwrapped into a cross like a cubemap will have 14 vertices.
    Unwrapped such that every tri has it's own UV island, 36 vertices.
    etc.

    There are other ways of texturing an object that do not require per vertex UVs, like using Triplanar Mapping, or a Cube map, or 3D texture, or PTEX, or some proposed techniques that use precalculated 3d curves to unwrap meshes in the shader.

    But the reality is the difference between 8 vertices and 24 vertices isn't really a big deal, and the default cube is very nearly the worst case scenario. Once you get up to higher polygon counts you're far less likely to see >3x jumps in vertex counts unless you're specifically going for a faceted look. (In which case you may want to look into using derivative based flat shading...)