# 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 on other sites
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).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982384

• 10
• 9
• 15
• 24
• 11