1
votes

As far as I know, OpenGL doesn't support per-face attributes [citation needed]. I have decided to use material files of .obj files and have already successfully loaded them into my project. However, I thought that materials were used per-object group and I realized that .obj format can actually use per-face materials. Therefore, a vertex group (or lets say, mesh) can have more than one material for specific faces of it.

I would be able to convert small variables like specular etc. into per vertex but the whole material can vary from face to face; illumination, ambient, specular, texture maps (diffuse normal etc.). It would be easy if the materials were per-mesh, so that I could load them as sub-meshes and attach corresponding materials on them.

How am I going to handle multiple materials for ONE mesh in which the materials are not uniformly distributed among the faces in it?

1
If all the faces are triangles attributes + glVertexAttribDivisor. But groupin faecs by material is probably more efficient unless you really have very few faces per material. - sbabbi
So, should I treat every "material groups" as sub-meshes? - deniz

1 Answers

1
votes

Firstly, what values do these per-face materials hold? Because, unless you are able to render them in a single pass, then you may as well split them into separate meshes anyway. If using index buffers, then just use a few of those, one for each material. Then you can set uniforms / change shaders for each material type.

The way my renderer works:

iterate through meshes
    bind mesh's vertex array object
    bind mesh's uniform buffer object
    iterate through mesh's materials
        use shaders, bind textures, set uniforms...
        draw material's index buffer with glDrawElements

Of course, you wouldn't want to change shaders for every material, so if you do need to use multiple shaders rather than just changing uniforms, then you will need to batch them together.

This isn't specific to obj/mtl, but any mesh / material format.