IB and sorting triangles

Started by
13 comments, last by Hodgman 13 years, 8 months ago
Quote:Original post by YogurtEmperor
Quote:How can I tell to directx the rendering order ?

Sort the triangles based off distance from the position of the camera transformed by the inverse of your world-view matrix.
Since you already know how to sort them I don’t why you are asking this, as you already answered your own question and you know how to do it.
Per-triangle sorting has always been the known and common method for solving this problem.


L. Spiro


Hey.... but what does it mean sorting ??? "Just sort the triangles" is not an answer to my question ^_°
I have a sorting algoritm, but WHERE and HOW do I have to output the sorted list ?


Quote:Original post by Exorcist
@OP:

You're right, you can just sort the IB. The Index Buffer by definition defines the order in which the verticies are used.


This is a kind of question I was waiting for. Anyway, can I reaily assume that the order of IB determines the actual rendering order ?
Advertisement
Modern GPU's *can* process pixels from different primitives (from the same draw call) at the same time, but that doesn't mean that they will. I assume that when blending is involved, they will only process one primitive at a time and insert a fence between primitives.

Go ahead and test it ;)
> Anyway, can I reaily assume that the order of IB determines the actual rendering order ?

Yes, Direct3D requires that this is functionally what has to happen.
Think about what would happen if it weren't. A vertex shader knows nothing about the type of primitive you are drawing, nor about how many vertexes are in it. It also doesn't know if any given vertex is the second in a triangle, the 17th in a strip, etc. If D3D were free to rearrange vertexes then you would have a situation where vertexes from separate triangles would arrive out-of-order, and you would end up with a mess on-screen. This obviously doesn't happen, so ergo the order as specified in the IB is the render order.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Quote:Original post by mhagain
Think about what would happen if it weren't. A vertex shader knows nothing about the type of primitive you are drawing, nor about how many vertexes are in it. It also doesn't know if any given vertex is the second in a triangle, the 17th in a strip, etc. If D3D were free to rearrange vertexes then you would have a situation where vertexes from separate triangles would arrive out-of-order, and you would end up with a mess on-screen. This obviously doesn't happen, so ergo the order as specified in the IB is the render order.
Though, after vertices are assembled into primitives, the GPU does render the pixels from multiple primitives in parallel; 2 overlapping pixels from 2 different triangles can be processed at the same time.

This topic is closed to new replies.

Advertisement