Sign in to follow this  
treeway

Material sorting and transforms

Recommended Posts

Hi In my engine, I sort each subset in the render list by material before setting each visible material once and drawing all subsets which have that material. I understand that this reduces the number of render state changes and increases performance but I want to know how this weighs up against the incresed number of transforms that need to be applied. for example if drawing a whole mesh in the "normal" way:
// Rendering in the 'normal' way
for each mesh;
   set world transform;         
   for each mesh.materials;
     set material;
       draw mesh subsets with current materal;
   next mesh.material;
next mesh;

// Rendering with material sorting.
for each material;
   for each subset with current material;
      set world transform;
      draw subset;
   mext subset;
next material;

I assume that setting a world matrix is much less expensive then setting up render states for a material / effect but is there a way to increase efficiency further? perhaps have one dynamic index / vertex buffer per material which contains the world-space vertex posisitons of all instances of the mesh subsets with that material? or would this require more processing then it would save?

Share this post


Link to post
Share on other sites
Know your data!
Notice there are usually two kinds of geometry.
Dynamic geometry tipically has other issues like uploading it and anyway, it's tipically used sparingly, no matter how you put it, when we speak about dynamic geometry an extra xfrom will be the last issue.
Static geometry (which I think makes a much bigger share) does not have this issue at all. It is pre-transformed by definition, just merge the batches (possibly strip-jumping them) and you're done.

Bottom line: do not pretend you can handle static and dynamic data optimally with the same code. It's not supposed to be that way - the loop above may be more or less ok for dynamic data (in which case this issue is not there) but it's absolutely overkill for static data (which shares the world xform by definition).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this