   Material System
  I'm trying to implement a material system and have narrowed it down to 2 objects being needed per draw call ( as well as transformations and whatnot). The Material object and the effect object. Where the material object holds a number of parameters and texture handles. And the effect is an object that holds handles to a vertex/pixel shader pair that is used to render the object using the materials textures and parameters.Now the way I have this at the moment is to have the material contain the effect as followsMaterial{Effect;List of paramters;List of Textures;}To keep things efficient when creating the material,( and after the effect is created) the Effect is searched for each material parameter, and a handle to that Shaderparamaterhandle is then stored in the material parameter. This is simply done by name, so its just a case of foreach( parameter p in material.parameters ){   p.shaderparameterhandle = material.Effect.GetHandleByname( p.name );}foreach( texture t in material.textures){   t.shaderparameterhandle = material.Effect.GetHandleByname( t.name );}then before each draw call, i just do something likeforeach( paramter p in material.paramters ){   p.shaderparameterhandle.set( p.value );}foreach( texture t in material.textures){   t.shaderparameterhandle.set( t.value );}This all works ok. But it doesnt allow me to use the same material on objects of different vertex types, such as having the same material being used for non skinned and skinned meshes, as a new effect has to be built for different vertex types. Even if I pull the effect object out of the material, the material parameters can still have handles to only one effect.I think that having to have different materials for objects of different vertex types to be bad design.Any suggestions?   
Quote:Original post by maya18222I think that having to have different materials for objects of different vertex types to be bad design.Material type is highly dependent on vertex type because certain material effects require different kinds of vertex data, so you might not get as much material sharing as you're hoping for.  However you should still be able to use the same material on multiple effects even if they have different vertex types, provided that all the effects have the material parameters.  A flyweight design will help you achieve this since the only data you need on a per-effect-instance basis are the handles, and possibly the values for each parameter.   