Advertisement Jump to content
Sign in to follow this  

Material sorting and transforms

This topic is 3849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!