I'm trying to implement a Material system in a small engine for training and I've got questions about materials.

Currently I've got that:

  • Material: A Material with array of Technique
  • Technique: Stock an array of Pass
  • Pass: Content RenderState (blend to apply, draw mode, face culling, …), Shader/Program and an array of Parameter
  • Geometry: Buffers, Indices, Vertices, ….
  • Parameter: A parameter is use to stock and share values with program (color, texture,…)

Now I'm not sure about that:

  1. A Material is something shared by Meshes or each Mesh have his own Material? In my scene, I've got 5 trees: two red trees and 3 blue shiny red trees (same Geometry). Each tree have is own Material or each tree have a reference to the same Material?

  2. The Material own by a Mesh is a copy of a Material or a reference to the original Material?

  3. In my Material I have texture offset and scale, it's useful for drawing a part of the Texture only, but how can I manage offset and scale if my Material is shared and each owner didn't use the same values? (In the case where all my objects are in the same texture atlas)

  4. If each mesh have his own Material instance (a copy of an original Material) how can I know if each Mesh have the same Material? (An ID per Material may be?)

Thanks a lot!


2 Answers 2


Well, if two meshes have the same exact material without change of textures colors..etc then each mesh will have a reference to the same material.

The usual approach to do this is to have list of resources of materials and each mesh can reference any material. If the original material changed everything that reference it will change. Now if you want to a certain mesh to have a slightly different version you can always clone the material as if it was a new one. It's also a good practice to have template materials that can be cloned and modified (see how unity3D handles this). Keep in mind that this doesn't mean textures for example should be duplicate, material is usually a set of references and settings to other resources.

Regarding the offsets, if it has a different offset, then you will need to duplicate the material. Keep in mind that the material is usually a set of references to other resources so it shouldn't be a heavy object.

If the mesh have a reference to a different object(material) that technically is a different material even if it has the same assets, materials can have a different id and name the name is usually for the human and the id for the engine.


You can split up your data into heavy and light. Heavy resources are things like shaders, geometry, and textures, which use a lot of memory and have a high cost associated with changing them. However, light data like texture offsets and blending colors are often changed and quick to change.

Thus, you can split up your "renderables" into two distinct sections. One section holds references to the heavyweight resources, and the other section holds unique, lightweight data.

This carries some additional benefits as well. For example, the sharing of heavy resources means that renderables can easily be batched together to cut down on state changes. As well, if enough objects have the same lightweight data signature and the same heavyweight resource references, they can easily be selected for instancing. Finally, the heavy resources, which would probably be handled by one or more resource caches, could be reference counted.


You must log in to answer this question.

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