Who here is or has used TRIANGLE_FANS for terrain

Started by
9 comments, last by darrenf 19 years, 8 months ago
I am now using TRIANGLE_STRIPS and don't like how my terrain engine can't render chaotic terrain very well. Would moving to fans help this? And if so are you using the central vertex as the value from the heightmap or are you using the values from the heightmap to make the four corners and making up some value to be the center vertex of the fan? Thanks [Edited by - MARS_999 on August 26, 2004 2:55:25 PM]
Advertisement
Hmm.. Mars, it is kinda hard to answer without more specifics, although I think you may not be considering the problem correctly. You can also have "as many triangles in a 1 by 1 square" with triangle strips, just start creating vertices in between?! By "chaotic" do you mean, not existing within a regular grid? Because that is the only reason I could see that triangle fans would have an advantage over strips. I'm assuming your heightmap is evenly spaced (is a regular grid), in which case you need to think about how to render triangle strips with more (smaller) triangles, rather than how you are rendering the triangles themselves. Remember that both fans and strips are just a shorthand way of specifying triangles...


regards,
darren
-darren
In general, you'll get just as good performance (if not better) with indexed triangle lists instead of the more awkward strips or fans.
Quote:Original post by darrenf
Hmm.. Mars, it is kinda hard to answer without more specifics, although I think you may not be considering the problem correctly. You can also have "as many triangles in a 1 by 1 square" with triangle strips, just start creating vertices in between?! By "chaotic" do you mean, not existing within a regular grid? Because that is the only reason I could see that triangle fans would have an advantage over strips. I'm assuming your heightmap is evenly spaced (is a regular grid), in which case you need to think about how to render triangle strips with more (smaller) triangles, rather than how you are rendering the triangles themselves. Remember that both fans and strips are just a shorthand way of specifying triangles...


regards,
darren


Yes my heightmap is a grayscale 0-255 heightmap and I am equally spacing the verticies. 0,1,2... So I am under the assumption that I need to do this to get more polygons to render my terrain if its chaotic. 0,.2,.4,.6,.8,1,... add more vertices instead of 0,1,2,3...? Thanks
well, i'm still a little confused as to what you mean by 'chaotic'. do you mean, a lot of variation in height, in other words, you are getting crappy looking 'stair-step' artifacts where there is a lot of variation? if so, then sorry for misleading you, but adding vertices is probably not going to help. unless you have some method of adding detail to your heightmap (simple bilinear interpolation, fractals, etc - some way of adding unique height values in between the values of your height map), you are just going to get smaller, but still flat and bad-looking, triangles. you should look into either increasing the heightmap resolution (in other words, increase the heightmap width + height but keep the 'interpreted' size the same, using the extra points as data in between), or perhaps using something besides bytes to store the height values. with only 255 possible height values, you are going to get really bad looking artifacts on anything with a lot of variation. i use unsigned shorts, which are fine for me, although you could even use floats and not worry about accuracy problems at all.

@OrangyTang -
sorry, but i'd have to disagree. i use indexed triangle strips in my terrain renderer, and it's a lot better for two reasons - faster, because the index lists are shorts and quicker to traverse; and smaller, because I need roughly 1/3 the number of indices to represent the same terrain, which is REALLY important once you start looking into large (>1024) heightmaps..
*edit* well i guess i stand corrected on the speed of strips vs individual triangles, as phantom pointed out.. although i would still probably put more weight into memory consumption than which method might be faster on some cards, i guess it depends on what you're trying to do..

but, as far as you are concerned, MARS_999, he is probably right, you shouldn't be worrying about strips or fans yet, just get your heightmaps looking nice with regular triangles first, its easier, and there isn't anything special you can do with strips + fans that you can't with regular tris.

darren

[Edited by - darrenf on August 27, 2004 2:41:28 PM]
-darren
Fans will probably introduce more trouble than they are worth. The way I see it you can do one of 2 things with these fans in a grid and both have flaws.

1: You can have the fan radiate from a corner in each grid unit, which is just as limiting as the previous method unless you can have as many vertices as you want in each grid square, which would require something other than a simple heightmap and be very dificult to line up smoothly with the surrounding grid units.

2: You can have the fan radiate from the center of the grid unit, being slightly less limiting, but as I see it, even more difficult to line up smoothly (in most cases immposible.) so it falls back to being just barely less limited than 1. Oh, and you'll still need that new map format :)


I think your best bet is to possibly increase the size of your heightmap, and reduce the size of your grid units. Then to get the speed back up you'll need to look into LOD algorithms.

throw table_exception("(? ???)? ? ???");

I've used them in a chunked quad-tree implementation. Each quadrant of a node has 16 triangles in it (plus up to 8 more around the edges to handle seams when neighboring quadrants are split). The center 8 triangles never change, so I render those with a triangle fan. The border triangles that go around the quadrant are rendered as a triangle list. I saw a noticeable improvement when I started rendering the center as a fan, which surprised me a bit because it required 5 times as many rendering calls. I had to render 4 separate fans (the the 4 quadrants) plus a list instead of just 1 list.

If you use DirectX, I hear that performance will drop because the overhead of each function call is higher, so it's more expensive to render only 8 triangles at a time. OpenGL is more efficient at rendering small blocks of triangles, so there was a gain.

Fans will not be any better than strips unless you can guarantee that, on average, the fans have more triangles in them than the strips you're using.
on the subject of vert ordering, from the presentation in my sig below for OpenGL performance tips;

* ATI cards favour tri-lists in strip order, costs more indices but easier to stich together
* NV cards favour tri-strips, stiches with degrenated triangles

Granted, you only really have to worry about this if you are transform limited, but its worth keeping in mind.
Thanks all for the ideas, I am going to have to go with the increase the heightmap x,y size and keep the area rendered the same I am thinking after reading all the posts. The idea of fans not aligning makes sense now that I played around with them in immediate mode... Nightmare...
Quote:Original post by darrenf
you should look into either increasing the heightmap resolution (in other words, increase the heightmap width + height but keep the 'interpreted' size the same, using the extra points as data in between)

darren


I am already using float for data types. The heigtmap resolution idea might work, but from what I am trying not sure if I am doing it right? Lets say the terrain size is 256x256 for the array that holds x,y,z values. Now the heightmap lets say is 512x512 which is two times as many verticies. Now the problem here is the size of the terrain is 256x256 so I increase that to 512x512 but the issue is now I am back to 1 to 1 vertices. So I took a scale factor and mulitplied that by x, z which are interger values 0, 1, 2, ect.... so if the factor is .5 now you have 0, .5, 1, 1.5, ect... for the vertices on x, z axis's. Is this the correct way to go about this? 512 x .5 is still 256 and not sure if I am getting what I thought I would? Thanks

[Edited by - MARS_999 on August 29, 2004 12:47:03 AM]

This topic is closed to new replies.

Advertisement