3
\$\begingroup\$

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?

\$\endgroup\$
  • 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 Apr 19 '16 at 21:16
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\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 Aug 21 '17 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.