Optimizing with Vertex Buffers

Started by
13 comments, last by HanSoL0 21 years, 1 month ago
if you''re not heavily dependent on mulitple lights based on the fixed-function pipeline, a vertex shader might increase your performance since all you''re doing is transforming the vertices. But I''m not completely sure about that...

''There''s something out there....something stupid...''
''I think I''m going to be ill. Is that a problem for you?''
''[You] overestimate my conscience by assuming that I have one.''
- Daria
Advertisement
But if you really want better performance you should look into frustum culling and occlusion culling.
The idea of frustum culling is not to draw anything that isn''t inside your view frustum. Hence reducing the amount of calls to glDrawElements, or the equal DirectX command, (DrawIndexedPrimitive, I think...).
And with occlusion culling, you don''t draw anything that is behind anything else, and not visible to you.
If you implement both of these, I think you will get a much bigger performance-boost, than by just concatenating your vertex buffers.
my occlusion code runs something like this:

1. i have a bit array corresponsding to each triangle in the level (its an fps game). at the start of each frame, the whole array is set to zero (i.e. all triangles are turned off) with a call to memset.

2. i use an octree to turn on all bits in the bit array representing triangles that are 1) in the view frustum and 2) facing the camera.

3. i take all the visible triangles and use occluders to further minimize the visible list.

4. after the occlusion code is done, i rebuild the vertex buffer from the bit array and make a single call to glDrawArrays.

actually, i havent implemented step 3 yet but its in the works. this is only for the level; it doesnt account for API calls to draw other scene elements such as characters, weapons, explosions, etc.

i understand this doesnt really answer hansolo''s question since he was asking about combining buffers, i just thought it might give him or other people ideas about how to further increase framerate.
Wow, thanks for all the great ideas guys. You''ve all been very helpful. I''ll let you know how it all turns out. Thanks again,

Ryan Buhr
Reactor Interactive, LLC.
www.reactorinteractive.net

Ryan Buhr

Technical Lead | Sector 13

Reactor Interactive, LLC

Facebook | Twitter

quote:Original post by HanSoL0
Right, thanks for the reply. I already do most of what you said. I only have one copy of each of about 10 asteroids and I just re-render more instances of each asteroid about 80 times or so. I''m not usin'' too much memory. I just want to reduce the number of DrawIndexedPrimitive() calls. Can this be done by putting all asteroid vertices into one vertex buffer, transforming individual groups of vertices, and rendering the whole vertex buffer with one call to DrawIndexedPrimitive()? Or am I thinking too far outside the box? Your help is much appreciated....

Ryan Buhr
Reactor Interactive, LLC.
www.reactorinteractive.net


I don''t known if using one big vertex buffer is better that using severlas smallers ones, i guess yes.

I understand that you need to draw severals objects, and each object need to be transfromed in the world (translated/rotated/scaled) using matrix, so ou transform the matrix and the call the vertex buffer, that for all objects.

Yes, YOU CAN transform each object your self and use a big vertex buffer to render all them.

the trick is this for each object that you are going to add to the big vertex buffer:

- transform the world matrix as you need for the object
- for each x,y,z vertex in your object transform it using the follow formula:

------------------------------------------
with matworld do
begin
xx:=(x*_11)+(y*_21)+(z*_31)+(1*_41);
yy:=(x*_12)+(y*_22)+(z*_32)+(1*_42);
zz:=(x*_13)+(y*_23)+(z*_33)+(1*_43);
end; //end matworld
------------------------------------------

(sorry about the pascal code)

x,y,z = are the original vertice in the object
_11,_21, _31 etc, are fields found in your "matworld" matrix,

xx,yy,zz = are your new transformed vertices as affected by the matworld matrix.

- now just add xx,yy,zz to the big vertex buffer.

that way you can have just one vertex buffer with severals different transformed object on in.

good luck,

tp.

This topic is closed to new replies.

Advertisement