PDA

View Full Version : vertex array speed question



HamsterofDeath
02-10-2003, 10:24 AM
i want to draw a lot of trees.
every tree has about 25 big leafs, and every leaf is a texture of a tree (looks ok), "cracked up" in the middle (like this : /\ , just a bit more like this -- , hope u understand what i mean).
i did this by using a quadstrip, 6 points, for every leaf.

at the moment, i'm drawing the trees on the fly la glbegin() (in java, gl* is about 2-3 times slower than a gl* in c++, but vertex arrays are nearly equal)


my question is : how to speed this up ?
a) should i put everything into a displaylist ? the disadvantage would be that i would have A LOT of displaylists needing a LOT of ram...
and i couldn't change anything inside them (wind effects etc.)

b) should i put everything into a lot of vertex arrays (i would need an array for every leaf). advantage : not much ram needed (every time the same texcoords & normals, just the vertex coords change)
disadvantage : a lot of calls.

c) put everything into a single vertex array, and use quads, instead of quadstrips ?

which is best ?

[This message has been edited by HamsterofDeath (edited 02-10-2003).]

zed
02-10-2003, 07:35 PM
well if all the trees are the same u could just store the tree once and do the following
pushmatrix()
translate
rotate
draw tree
popmatrix

FWIW (ive never seen anyone mention this before)
LOD without any extra storage requirements only the highest resolution model is needed

i do the following for my l-grammer trees.
LOD = 1 - (tree distance from viewer) scaled to the number of indices etc
glDrawArrays(0, LOD )

BTW u will need to construct your trees cunningly

JustHanging
02-11-2003, 02:37 AM
Hi,

I'd turn them into triangles and draw a tree with a single GL_TRIANGLES array. But if it's quad based, GL_QUADS might do just fine.

Zed's lod idea sounds simple and efficent in the cases where it can be used. Would be better, if you had textures with different leaf densities, so that when you take away half of the polygons the others get twice as dense to compensate. And don't forget the mighty billboards, they're great for distant trees.

Just an artistic note I've said before, but you should change your leaf polygons from > to >- . That way you can eliminate the sharp edges that are visible in your trees. It's well worth the extra polygons. Also, if you are running for realism, consider recieving the leaf imagery from actual photographs, that makes the trees look a lot more real.

-Ilkka

HamsterofDeath
02-11-2003, 08:23 AM
the trees don't look the same

the comversion to triangles isn't a good idea : it would slow down everything.
a quad strip with 6 points will be split up into 4 triangles with 3 points (=12) each so i'll slow down my engine...

what do you mean by >- ?
a screenshot would tell more than 1000 words ^^

well, i think i'll change the quad strip to 2 quads, that won't change much (this way it's optimized for every cards vertex cache, because point 3+4 are points 5+6), but i would need WAY less calls (only 1 call for all leafs instead of a call per leaf -> i'm storing alle leafs in 1 texture)

as for the lod, i'm waiting for pics

edit : is it possible so manage displaylists so i can compile those i need at the moment and clear them if i don't need them any more and so on ?

[This message has been edited by HamsterofDeath (edited 02-11-2003).]

Catman
02-11-2003, 10:38 AM
a quad strip with 6 points will be split up into 4 triangles with 3 points (=12) each so i'll slow down my engine...
If you use glDrawElements() you won't have 12 points. You just specify the 6 points and then you make 12 indices...


edit : is it possible so manage displaylists so i can compile those i need at the moment and clear them if i don't need them any more and so on ?
I think that would cause a little delay when you create the lists, but maybe it would be OK for you...

JustHanging
02-11-2003, 11:02 AM
Originally posted by HamsterofDeath:
a screenshot would tell more than 1000 words ^^

Always ready to present my work!

I tried to draw the polygon edges and stuff in it, but honestly it still doesn't look too explanatory. What can you do, the whole thing was made to fool our perception from the start! The leafs are made from shells on top of each others, I think there are 5 shells in that tree. I included a couple of images of a single shell to better show the idea.

Image: http://www.hut.fi/~ikuusela/images/trees.jpg

-Ilkka

[This message has been edited by JustHanging (edited 02-11-2003).]

HamsterofDeath
02-12-2003, 12:43 AM
Originally posted by Catman:

a quad strip with 6 points will be split up into 4 triangles with 3 points (=12) each so i'll slow down my engine...
If you use glDrawElements() you won't have 12 points. You just specify the 6 points and then you make 12 indices...


edit : is it possible so manage displaylists so i can compile those i need at the moment and clear them if i don't need them any more and so on ?
I think that would cause a little delay when you create the lists, but maybe it would be OK for you...



don't i have to put every vertex that has to be drawn in an array ?
so, instead of
begin
glquad
glvertex3f(a,b,c);
.
.
.
glvertex3f(a1000,b1000,c1000);
end;

i create an array of length 3000 and put all floats in it ?
array[] = a,b,c,a1,b1,c1......c1000 ?

i think i'll play aroung with trees and leafs and fractal trees and some spiral-quad-strip-leaf things...



[This message has been edited by HamsterofDeath (edited 02-12-2003).]

JustHanging
02-12-2003, 01:17 AM
No, if you use drawElements, you only have to store each vertex once. Then you have another array which contains indice to the vertex array. In your case the vertex array would consist of 6 vertice and the index array would have 8 indice for quads, or 12 for triangles. If you use compiled vertex arrays with that, each shared vertex gets transformed only once.

As for the fractal trees, you'd better look into l-systems, they allow for a lot more flexibility.

-Ilkka

HamsterofDeath
02-12-2003, 08:09 AM
sounds good.. where to find a tut about this ?

and, if there is one : where to find a tut about display list management ?
i only know how to compile several lists, but how to replace them, delete them etc ?

[This message has been edited by HamsterofDeath (edited 02-12-2003).]

[This message has been edited by HamsterofDeath (edited 02-12-2003).]