Particle Batch calls with degenerate verts

Started by
3 comments, last by WinstonPennypacker 16 years, 8 months ago
Hey all, I'm working on a GPU particle system and am currently batch drawing every particle in the same vertex buffer as a list of triangles. So thats 6 verts for each particle. I'd like to switch to using triangle strips if I can, but then it would try to draw as one gigantic strip, instead of seperate quads. I realize I could use indexing to fix this, but I've heard of another way and was wondering if anyone had any solid info on it- I've heard that by adding a single degenerate ( not meant to draw ) vert to each particle, you can manipulate those to fix the problem and visually produce the look of seperate triangles ( or particles ) with one huge strip? I know I've heard of this somewhere before, but does anyone have any info on how to do it, or is it as easy as just adding the vert? Thanks.
Advertisement
A degenerate triangle is one with no area. So two of the points must be idential. For example:
(0,0,0)
(0,0,0)
(1,0,0)
If you tried to draw it out you would notice the triangle has no area. Video cards can quickly throw these triangles to the side. Which means to connect two seperate things in a tristrip you can use two degenerate triangles to setup the last two points fo that the next triangle has something to work with.

Does that make sense?
Yes, for the simple case of stitching a bunch of quads together, it's not hard at all. You can draw the whole thing as one big tri-strip. Each of your quads is really two triangles (which already form a mini-strip). If you want to draw multiple quads, you just send the first and last vertex of each quad twice. (Ignore the very first and very last verts).

So if your verts for the first quad are ABCD, and the next one is EFGH, etc... then your tri-strip is:

ABCDDEEFGHHIIJKL...

The triangles that end up being drawn are:

ABC, DCB (The first quad)
CDD, EDD, DEE, FEE (Degenerates)
EFG, HGF (Second quad)
GHH, IHH, HII, JII (Degenerates)
...

As you can tell, you end up drawing MANY more triangles than before. It's very likely that this isn't going to be any faster than using tri-lists - stitched strips aren't really in fashion these days (compared to simpler indexed tri-lists). If your hardware supports it, you can also use the 'primitive reset index', which lets you stitch strips together with a single vertex, rather than two. That's STILL probably not worth it in this case, because the per-strip setup cost could easily get out of hand.
I recently started a thread related to this. The results were quite surprising because it's actually a fair bit faster to render indexed triangles than triangle strips. Plus, indexed triangles are a much more convenient data format to work with.

A big performance win with indexed triangles is obtained from the usage of the post T&L vertex cache which means the GPU doesn't need to do as much work on the vertices (T&L).

Still, if you must use triangle strips then I would recommend taking a look at TriStripper (http://users.pandora.be/tfautre/softdev/tristripper/) it's a great little library, it's open source and completely free for any use. On the website there is also an overview of the algorithm which is an excellent reference on how to do something like this - though you must bear in mind that the majority games performance is CPU bound, and stripping your verts in your rendering pipeline is going to chew up even more of those precious cycles.
Awesome, thanks a lot everybody.

This topic is closed to new replies.

Advertisement