State changes and sorting speed issue


I’m doing sorting on 20000 to 50000 polygons. I’m using a STL set to sort my polygons by material, where each materials holds information about texture, lighting properties, pixel- and vertexshaders.
The STL set is killing performance on my GForce2, so I was actually wondering which algorithm I should use to do the sorting?

Links/examples to algorithms would be highly appreciated.


No, STL isn’t killing the performance… it’s because you’re sorting polygons by material instead of objects.

You should do everything at object level instead of polygon level (sorting, culling, rendering, etc)

If you need more materials per object you could try creating submeshes with different materials…

Actually I’m using an Octree for culling, so what u are suggesting is to split a landscape up into objects and then put the objects in the octree leafs instead of the polygons?


I agree with you for the per material sorting.

On the other hand, if one of these materials is transparent, you need to sort the triangles on their Z value to display them correctly, don’t you ?

I was wondering if anyone has ever come accross this problem i.e. having to sort a lot of triangles to get a good transparency effect. Or is the common solution trying to have as little transparent polygons as possible ?

Sorry if this sound dumb !



what i do is presort everything that can possibly be in the scene beforehand. then duruing a frame if theres any instances of that state i render those then go onto the next one
(btw i do also sort each state’s meshes by zvalue per frame but u can leave this part out it really doesnt make that much of a difference)

also for transparent stuff
normally u render all solid stuff
then render all transparent stuff after that

depending on what blending methods u use sometimes u need to sort or u can ignore that esp if its a fast moving particle system.
the only case where i sort is by huge transparent polygons eg water surfaces.