Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Explained] How many verices cube needs? 8?, 16? Nah ... 24!? What?

Discussion in 'General Graphics' started by Antypodish, Aug 21, 2018.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    upload_2018-8-21_2-6-40.png

    So what the heck story is about Unity Cube, with 24 vertices?
    Is seriously 8 not enough? I think Unity in past used double of that, which was 16, if I am correct?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    6 planes with 4 verts each = 24.

    Of course the vertices can be shared, but if they're shared then they'd also share normals and if they share normals it won't really look like a cube anymore.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Oh ok, And I think this applies similar, to vertices color, per side?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    you can have 8, but you would need a shader specifically for hard edges and I've no idea what kind of mess the uvs would be in. When using modelling packages, they typically disguise that they do the same thing.
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    How big/small impact of tripling number of vertices is, on ECS performance, with many thousands of cubes?
    Would it be worth use imported Cube mesh and UV, from external 3D software? i.e. blender?
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Thx. I do wonder however, how 3D software manage (3DS Max, Blender), to keep 8 vertices only per cube. Unless trick is that other 16 vertices are hidden normally behind the scene, while exposing only 8 for manipulation.
     
    Propagant likes this.
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    DirectX and OpenGL both require 24 verts per cube if you need to provide colors or textures.

    -edit-

    I should add, as far as I'm ware there's no real performance advantage of having less verts [if your triangle count doesn't change] except for less memory being utilized.

    The shader still needs to render every triangle. If you weld/reuse verts the number of triangles rendered doesn't change, just the number of verts stored in memory.
     
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Well, does makes sense. Which means vertices "trickery" (by pairing groups of 3) is used in the 3D software mesh rendering. Learning every day ;)
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    They don't, they lie.
     
    Micz84 and Antypodish like this.
  11. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    448
    Exactly, what I wanted to say. I had to explain this to the 3d artists in my team because they were saying that their models have fewer vertices.
     
  12. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    The 3D software is independent of how the model is rendered. It normally uses per surface normals. Only for realtime rendering the vertices need to be split up and eg quads and higher order polygons have to be triangulated. So they don't exactly lie. Eg for raytracing the per surface might be used instead.
     
    AcidArrow likes this.
  13. Devilbox-Games

    Devilbox-Games

    Joined:
    Jul 3, 2012
    Posts:
    205
    This is a bit of an aside: I'm don't know about other software but 3DSMax doesn't technically lie, it just has a far more complex data structure for meshes than games and real-time rendering do.

    A cube will have 8 vertices but those vertices are just positional data. It has an entirely separate set of definitions for texture vertices and another for colours, etc. The way it stores normals are even more complex with vertex normals, face normals, smoothing groups, etc. Internally it associates the parametric vertices with the "actual" vertices. When it comes to rendering it translates all that data into the appropriate structure for the rendering method, after all it's not just for rendering in realtime via DirectX or OpenGL in the viewport. Different exported file formats also handle the data in different ways which can be incompatible with what we as game developers know to be "correct".

    So when you select and move a vertex on a cube you are selecting and moving just one actual vertex in terms of the data, even though what's being rendered in the viewport ends up as 3 vertices pushed through the graphics API. The graphics API's representation of the mesh is entirely separate to the DCC's representation of the mesh which you're actually manipulating. I guess it's all technicalities but saying the software lies isn't a good representation of what the software is actually doing, especially when the software was designed before said graphics APIs actually existed on the platforms it was originally released on.
     
    Qbit86, Antypodish and AcidArrow like this.
  14. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Agreed, I was exaggerating.

    In the software's context they show the correct number of vertices. (and some do tell you the OpenGL viewport numbers as well. Modo does, but only for tris)
     
  15. vitautart

    vitautart

    Joined:
    May 3, 2018
    Posts:
    29
    It's just computer graphic topic.
    One vertex consists of information about:
    1. Position
    2. Normal
    3. UV Coordinates
    4. Other Stuff (color, tangent, binormal, etc)

    If two vertices have the same position, normal, uv coordinates, other stuff, you can weld them together, so you get 8-vertices cube. Try create in blender for example cube with smooth shading, without uv coords (this means that all three vertices in one corner have same position, same normal, and same uv coords), and you will get 8-vertices cube after exporting obj file to unity.
    P.S. Interesting thing that unity's obj exporter-parser welds vertices manually, even if obj file describes all 24 vertices.
     
    Antypodish likes this.
  16. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    ...It will look like low-poly sphere.