Sign in to follow this  
Isolier

Vertex Arrays

Recommended Posts

Hello, In my current project I render terrain based off height map data, I am using vertex arrays however because all the vertices are in one long array, it "connecting" if you will the right most polys with the left most polys instead of creating individual rows. So the terrain renders properly except that it is trying to render a triangle between the vertices on the oposite side of the map. What am I doing wrong here?

Share this post


Link to post
Share on other sites
Split the rows with degenerate triangles (triangles with zero area).

Simple example mesh:
0----1----2
| / | / |
| / | / |
3----4----5
| / | / |
| / | / |
6----7----8
Index array without degenerate triangles:
0, 3, 1, 4, 2, 5, 3, 6, 4, 7, 5, 8

Which renders triangles:
0-3-1,
3-1-4,
1-4-2,
4-2-5,
2-5-3, (erroneous)
5-3-6, (erroneous)
3-6-4,
6-4-7,
4-7-5,
7-5-8


Index array with degenerate triangles:
0, 3, 1, 4, 2, 5, 5*, 3*, 3, 6, 4, 7, 5, 8
(indicies with *'s are added indices to generate degenerate triangles)

Which renders triangles:
0-3-1,
3-1-4,
1-4-2,
4-2-5,
2-5-5, (degenerate)
5-5-3, (degenerate)
5-3-3, (degenerate)
3-3-6, (degenerate)
3-6-4,
6-4-7,
4-7-5,
7-5-8


Enigma

Share this post


Link to post
Share on other sites
This makes pefect sense, however would it be easier to use glDrawElements to draw one row at a time? Would doing it this way negate most of the speed increase gained from using vertex arrays in the first place?

Share this post


Link to post
Share on other sites
You can also order then so the triangles connecting rows only have the back side showing, and dont get drawn when using frontface culling.

The more you draw at a time, the greater preformance you will get. When using strips i have found it best to create degenerate triangles than dividing up arrays so none are needed.

But buy dividing them into groups you allow your self the option to not draw a group at a time if they are off the camera. (fustrum culling)

Share this post


Link to post
Share on other sites
Quote:
Original post by skow
You can also order then so the triangles connecting rows only have the back side showing, and dont get drawn when using frontface culling.

Beware that the front faces of those triangles can become visible though, consider the following:
side view:                plan view:

\ / +---+---+
\ / | / | / |
----- +---+---+
| / | / |
+---+---+

If you rely on back face culling then you will actually have triangles covering the top of your terrain:
_________
\ /
\ /
-----

(_ = backfacing triangles)

If you look down on your valley the triangles will be back-facing and will be correctly culled, but if you are in the valley and looking upwards you will be looking at the front faces of the triangles. Those triangles can also become visible from other angles if the edges of your terrain are irregular, but such things are beyond my limited ascii-art skills [lol].

Enigma

Share this post


Link to post
Share on other sites
Personally, I'd forget about triangle strips all together and go with indexed triangle lists, you require more index data however vertex data stays the same size and you can still take advantage of the various caches on the gfx cards.

So, from Enigma's inital example;

0----1----2
| / | / |
| / | / |
3----4----5
| / | / |
| / | / |
6----7----8

To render this you'd need an Index array of:
0-3-1,
3-1-4,
1-4-2,
4-2-5,
3-6-4,
6-4-7,
4-7-5,
7-5-8


Each group of 3 indices creates a triangle, as each group generally shares 2 points with the group before it you get those values from the post-T&L cache.

Share this post


Link to post
Share on other sites
Phantom,

I don't understand how this would yield a performance benefit. Specifically, it doesn't seem to me that you would be able to use a vertex list with a vertex array like that. How would you render your triangles if not with tristrips? Just G_TRIANGLES and a build list? Am I missing something or totally off base here? I don't mean to sound argumentative, as I am definitely not in the know, I am just trying to understand...

Share this post


Link to post
Share on other sites
Quote:
Original post by Isolier
Specifically, it doesn't seem to me that you would be able to use a vertex list with a vertex array like that. How would you render your triangles if not with tristrips? Just G_TRIANGLES and a build list?


When you do a vertex array, TRIANGLE_STRIP is one of many things you can pass in. Other things such as QUAD, TRIANGLE, TRIANGLE_FAN, etc.

But phantom does make a good point with a vertex cache, the preformance gained by using strips over normal triangles is very minimal if at all. The real preforance gain is using arrays over glBegin calls.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this