0

iam using COLLADA for loading 3D assets, and i want to interlace position, normal and texcoord data into one array of struct and use vertex index to draw the object, however the vertex attributes are of different count (ex: position has 24 values, normals have 36 values ..etc), i was able to load models by rearranging the attributes into the predefined struct array, however this time i have to load models without using the index buffer, is it possible to interlace those attributes into one array and use index buffer? what is the best approach to load models that would give the best performance gain.

my struct would look like this

struct vertexAttribs
{
    glm::vec3 position;
    glm::vec3 normals;
    glm::vec2 texCoord;
}
BulBul
  • 957
  • 2
  • 18
  • 34

1 Answers1

0

using an index buffer is a all or nothing deal. Either all attributes use the index buffer or no attributes use it.

You would have a VkVertexInputBindingDescription with stride = sizeof(vertexAttribs) and a VkVertexInputAttributeDescription for each attribute in it with matching offsets and formats using the same binding as the VkVertexInputBindingDescription.

ratchet freak
  • 44,814
  • 5
  • 55
  • 99
  • The problem is the position and normals count do not match the count value are different, in my example position has 24 values and normals have 36 it is not possible to interlace them unless i use index buffer for each value to re arrange them into a new buffer array, but when i do so i have to avoid indexed drawing command . – BulBul Jun 17 '17 at 15:38
  • that's impossible there is only one index buffer and all attributes use the same index. You will need to duplicate the data. – ratchet freak Jun 17 '17 at 16:14
  • thank you i guess i will stick with normal drawing rather than indexed drawing, as a final question do you have any idea why would a cube model have 24 unique position values but 36 normal values? shouldn't they be consistent with each other. – BulBul Jun 17 '17 at 17:30
  • 1
    At corners of the cube, you only need one position, but you need a normal per cube face. If you tried to use a single normal, it would probably point at the average of the normal directions of the three adjacent faces, causing any calculations involving the normal (e.g. lighting) to treat the corners and edges as blending smoothly between the faces rather than being hard/sharp. – Jesse Hall Jun 19 '17 at 17:32