Texture Sorting

Started by
2 comments, last by cruZ 22 years, 5 months ago
I have rather huge terrain, and I was wondering how much a texture change (SetTexture in D3D) affects the overall performance. I mean if I have a lot of different visible textures on my terrain, would it be faster to sort the polygones by textures and draw polys with the same texture first? Or is it just a waste of time to sort them?
Advertisement
It''s usually not a waste of time to sort them. Try this - draw all the unsorted polygons setting textures whenever you need to (the mostly worst case). Now try drawing all the polygons, but only set the texture once (the best case). Is there a difference? Is it significant? If so, then you''ll probably want to sort.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
If you use index buffers its not to hard to sort the triangles, even if they are in the same vertex buffer. Just use one index buffer per texture. Note that at least on by Geforce 2, index buffers are limited to words (16 bit) - reference 65,000+ vertices (no dword), so if you have more than that, you need to split up the index buffer.
Alternatively you can just store all the terrain textures one big texture and adjust coordinates accordingly (4 64x64 textures in one 128x128 -- but leave a guard area for mip mapping and filtering or you might get some wierd edge effects).
I don''t know how else you were going to do this. You certainly do not want to render each triangle one at a time and change textures each time -- that will take forever!
Good point - either presort the actual vertex buffer and/or create a sorted index buffer (which is very different from a sordid index buffer). You could do it without an index buffer if you sorted the vertex buffer and then rendered different ranges, but you should be using an index buffer anyway.

In any case, think groups of triangles, not individual triangles...
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement