Archived

This topic is now archived and is closed to further replies.

MatuX

IndexBuffer elegancy problems

Recommended Posts

Hey, I''m having some technical problems concering "correct usage" of IndexBuffers... I''m drawing a simple mesh (http://matux.hypermart.net/mesh.gif) using a Vertex Buffer and an Index Buffer. The VBuffer is ordered this way: http://matux.hypermart.net/vertexbuffer.gif and I''m indexing the vertices in this order: http://matux.hypermart.net/indexbuffer.gif. As you can see, from 7 to 8 and 15 to 16 I''m redrawing a whole line! Techically this is overdrawing, theoretically is bad, and practically you won''t notice this may be a real problem until it''s very late. Plus, the bigger problem which concerns me is that I have to tell DrawIndexedPrimitive to draw 22 triangles instead of the 18 that''re shown! So, this already scared me off and I''m trying to figuring out a way I feel it may be the RIGHT way to index the vertex buffer. I tweaked the code a little bit and came out with this: http://matux.hypermart.net/indexbuffer2.gif, which solves the overdrawing issue, I''ve to specify 2 tris less than before (20, but there still are 18 tris!) and the mesh seems like something went wrong (the second row looks bad). All the pictures were taken with the WIREFRAME fillmode.

Share this post


Link to post
Share on other sites
I think as far as triangle strips go you''re doing the best that i could possibly think of... I''ve had as similar problem when i was making a simple terrain type program... i ended up just using trianglelists it actually worked better for what i was doing because then i was able to decide for each square in the terrain how the two triangles would be positioned... im not exactly an expert on Direct3d but from what i''ve read, most people figure that the performance difference between strips and lists isn''t worth your time... but like i said if i was going to use strips i would have done exactly what you already have

Share this post


Link to post
Share on other sites
I may use a trianglelist for the index buffer... But isn''t the whole point of using IBuffers lost?
I mean, the IBuffer is used to avoid vertex repetition on the vertex buffer, but if I build the ibuffer as a trianglelist I''m not only misusing the hardware''s vertex cache but I''m already overdrawing and overprocessing triangles!

I mean, theoretically, there should be a LOT of performance difference between TRILIST and TRISTRIP if you''re rendering ~100,000 (or more) triangles for a landscape!

Share this post


Link to post
Share on other sites
The whole point of using an index buffer is not lost... if i were to render a landscape with trianglelists and no index buffer at all, i would need to redundantly add many many vertices... my vertices are each 20 bytes that would be rediculous... with an index buffer i only need to define the minimum vertices that i need

You''re right theoretically there should be a large difference in performance... but every time i read about lists vs. strips most people say that there isn''t... i don''t understand why but i think i believe it... what i would suggest is possibly rendering the same thing in lists and then in strips and compare the frame rates... maybe a much larger mesh, like you say, so you get a good idea

Share this post


Link to post
Share on other sites
>The whole point of using an index buffer is not lost... if i
>were to render a landscape with trianglelists and no index
>buffer at all [...]

I didn''t explain correctly... I meant, doesn''t a trilist IB counteract a tristrip VB? If so, why using an IB at all?

But as you said, I will test this.

Share this post


Link to post
Share on other sites
quote:
Original post by MatuX
I didn''t explain correctly... I meant, doesn''t a trilist IB counteract a tristrip VB?


What do you mean by "tristrip VB"? Your vertex buffer usually just contains all vertices, in one order or another.
quote:

If so, why using an IB at all?


Vertex cache and memory savings. If you switch to trilists, in this particular program I would think that GeForces won''t pull any vertices from VB twice. Also, for duplicate vertices you need sizeof(WORD) additional bytes instead of sizeof(CUSTOMVERTEX). Tristrips may be more efficient, but I heard that in many cases modern hardware detects tristrips in trilists anyway. I agree with TempusElf that tristrips in many cases aren''t worth developer''s time.

Share this post


Link to post
Share on other sites
It''s doesn''t counteract it but it certainly doesn''t make it a WHOLE lot better. If you are rendering a 300+ model, using an Index Buffer than references a Vertex Buffer(list) will help you no matter what (I switched to this method and on a 500 poly model got a 20 frame per second boost, result will vary though).

You''re right though, a triangle strip is COMPLETELY more efficient and the best way to do it. The Dreamcast I believe would convert a scene into triangle strips before it would render (it used a modified DirectX API btw). It makes sense but there is a large amount of precomputation required and pretty complex (not too bad) algorithms involved in order to convert a normal indexed triangle list model into an indexed triangle strip model.

Just be happy with the index buffer implementation for now, but if you wanted to make a quake/doom or unreal engine killer, it is probably a good idea (since your models would be so well optimized, practically no overdraw).

Share this post


Link to post
Share on other sites
the actual performance difference between tri strips and indexed tri lists will be quite small, especially if the list has been optimized.

This is the word of the D3DX team, and it seems to be confirmed by my own (extremely informal) tests.

The D3DX folks have the opinion that stripifying isn''t really worth the effort and I haven''t found any reason to disagree with them.

Share this post


Link to post
Share on other sites
So, you guys say that if I take care of all the normal performance issues (<32 bytes FVF, completely ordered VBs, etc. which I already took care ) the perf difference between a stripped VB and an indexed list will be minimal? Ok.. That''s new and certainly is interesting.

Dirge, I''m not aiming to a Quake, but I do for a Neverwinter Nights. I mean I don''t expect to make a NWN (or maybe I do ), but I think it''s time to start programming the way it HAS to be done to be professional work.

In the other hand, practically, I ain''t having ''problems'' with indexed strips! I''ve already implemented it and it works fine. Back to the first post, what concerns me is the way I''m doing it, it may not be the right way to do it!
Take a look at
http://matux.hypermart.net/indexbuffer.gif
The numbers are the index order (0 is the first one, 1 is the second, 23 the last). Just notice these two issues:
Overdrawing: from the index 7 to 8 and 15 to 16 I''m overdrawing an entire line!
PrimitiveCount: You just see 18 triangles, I''ve to tell DIP to draw 22, is DIP actually drawing 4 triangles more?

Thanks for all your help, guys

Share this post


Link to post
Share on other sites