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. Dismiss Notice

Question What is the difference between baseVertex and firstVertex in SubMeshDescriptor?

Discussion in 'General Graphics' started by RamType0, Dec 13, 2022.

  1. RamType0

    RamType0

    Joined:
    Sep 11, 2018
    Posts:
    67
    What is the difference between baseVertex and firstVertex in SubMeshDescriptor?

    They look like completely same, but none of them marked as obsoleted, nor explicitly documented that they are same.
     
  2. georgerh

    georgerh

    Joined:
    Feb 28, 2020
    Posts:
    72
    I think the documentation is wrong. firstVertex is the index of the first referenced vertex in the vertex buffer.

    Even though you run through the index buffer sequentially, the referenced vertex indices could be all over the place (non-contiguous). firstVertex and vertexCount are the range of the vertices in the vertex buffer that could potentially be referenced - but there might be some in between that are not actually referenced.

    Code (CSharp):
    1. int firstVertex = int.MaxValue;
    2. int lastVertex = int.MinValue;
    3. for (int i = 0; i < indexCount; ++i)
    4. {
    5.     int idx = baseVertex + indices[indexStart + i];
    6.     firstVertex = min(firstVertex, idx);
    7.     lastVertex = max(lastVertex, idx);
    8.     Vertex v = vertices[idx];
    9. }
    10. vertexCount = lastVertex - firstVertex + 1;
    11.  
    So indexStart and indexCount is the referenced range in the index buffer and firstVertex and vertexCount is the referenced range in the vertex buffer.

    That's my understanding. Somebody correct me if I'm wrong.
     
    Last edited: Dec 13, 2022
    RamType0 likes this.
  3. georgerh

    georgerh

    Joined:
    Feb 28, 2020
    Posts:
    72
    Last edited: Dec 13, 2022
    RamType0 likes this.