0

What is the correct way to sort polygons so that they blend properly? The basic concept I think is to render the furthest polygon first back to closest in order. But what about cases of intersecting polygons?

meds
  • 21,699
  • 37
  • 163
  • 314

2 Answers2

1

What is the correct way to sort polygons so that they blend properly?

Sort them back to front.

But what about cases of intersecting polygons?

Simply ... don't do it. If you have no choice then you will have to split the polygons along their intersection as you go.

Edit: Its worth bearing in mind that finding the intersections and splitting will be very slow. You could use some sort of acceleration structure to aid you.

Its quite common to use a BSP to sort and split static transparent polys.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • But then what can I do about things like ID3DXMesh's? Am I supposed to lock the vertex buffer and rearrange the vertices? – meds Nov 01 '10 at 11:08
  • @Meds: Effectively, yes. You shouldn't be storing transparent tris in an ID3DXMesh really. You want some sort of better structure for that ... – Goz Nov 01 '10 at 11:19
  • I see, what particular properties should the struct have? (I'm assuming you mean vertex struct). – meds Nov 01 '10 at 11:34
  • 1
    @Meds: No I don't mean a vertex struct. Well basically all you are sorting is indices. So you "could" just update your index buffer. But it will save time (over locking the vertex buffer) to have the vertex positions somewhere in normal memory so you can sort them without touching the VB and then you just update the index buffer and use that. – Goz Nov 01 '10 at 11:38
1

Frankly I would go for depth peeling and compositing passes. I have seen some implementation of this algorithm and most of the time peeling 2 or 3 layers is "good enough".

This will also save you from having to managed different data structures for storing your meshes. One drawback is that it can be a bit performance intensive, for example if you have a lot of transparent meshes.

elmattic
  • 12,046
  • 5
  • 43
  • 79