0
\$\begingroup\$

I'm a fresher on engine programming. I have a question of how we can get the vertices buffers of vertex formats from the mesh file.

For example, in OBJ file or FBX file, we save the positions, normals separately. So the whole mesh file is a structure of different arrays which contain the different attribute of the vertices.

But when we offer those data to the graphics card, we'll offer an array of vertex structs, here the vertex struct contains the position, normal, UV... for one vertex.

So, suppose we want to generate different vertex buffers for different shaders from the mesh file(the struct of arrays), then I think we can use 2 solutions:

  1. generate a different array of structs, here the different struct will be the different formats of vertices. The problem is: It takes a lot of memory to save the different vertex buffers.

  2. generate a general array of struct, here the struct contains all of the vertex attributes we can get from the mesh file, and use offset to get the correct data for different vertex format. The problem is: will it be slow for shader program to access the vertex data?

Which one is the better way to do? Or is there any better solution? Again, I'm just a fresher, So I hope my description is clear enough for the problem :-)

Thank you all very much!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If you have lots of different input formats then #2 would probably make more sense, however you might end up with a lot of overhead (however I think more modern systems like UE4 do something like this), which leaves #1. However, most games typically do not vary the vertex formats between shaders or have models that have multiple input formats (You are more likely to duplicate your shaders for each input type).

For example, all skinned models might use the skinned vertex format, and any shaders that can work on skinned models would use that vertex format.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks a lot for the answer! I really should read some source code of industry-level game engines, like UE4. I think may just go #1 right now, since I don't think I should use a lot of different vertex formats. \$\endgroup\$
    – LLL
    Commented Apr 21, 2016 at 6:48
  • \$\begingroup\$ you should look at the shader blueprint editor, it will give you some idea (look at the inputs/outputs) \$\endgroup\$
    – CobaltHex
    Commented Apr 21, 2016 at 8:27
  • \$\begingroup\$ Thanks! I have a little experience with UE4, but I didn't use its awesome material system. Anyway, thanks a lot! \$\endgroup\$
    – LLL
    Commented Apr 21, 2016 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .