I'm currently implementing an Object Loader for the Wavefront File Format (*.obj). When exporting a model (with associated materials) from blender, a material for a group of faces is specified like this:

usemtl MyMaterial
s off
f 2/1/1 4/2/1 3/3/1
f 1/4/1 2/1/1 3/3/1

Since each material consists of (at least) 3 components for each of ambient, diffuse specular color and also shininess (which totals up to 10 floats) I would consider it to be a tremendous waste of memory to store all of these values for each vertex.

Does OpenGL provide us with a more elegant/viable way to achieve the same result with a more reasonable memory consumption or do I have to swallow the bitter pill?

  • 4
    \$\begingroup\$ Yes, Uniforms. The simplest implementation would then need N Draw-Calls per mesh, where N is the number of unique Materials of the mesh. \$\endgroup\$
    – dari
    Commented Apr 19, 2016 at 21:16

1 Answer 1


The simplest implementation would be to do N Draw-Calls per mesh (where N is the number of unique Materials of the mesh). Each time passing next meterial settings via shader uniforms.

Another approach could be to add material index attribute to each vertex and pass an array of N material settings as uniform. Then you can choose appropriate material properties in shader.

Note: Both solutions do not handle materials transitions between vertexes within single polygon.

  • \$\begingroup\$ You can get material transitions with a flavour of the second option, where each vertex stores two material indices and a blend factor to interpolate the results of each. The tricky bit is that all vertices in each triangle need to agree on the ID in any material slot that has a non-zero weight inside the triangle, which can require extra vertex splits. \$\endgroup\$
    – DMGregory
    Commented Aug 21, 2017 at 13:54

You must log in to answer this question.

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