Jump to content

  • Log In with Google      Sign In   
  • Create Account


Better FPS with high-poly terrain


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 30 June 2013 - 12:01 PM

I recently increased the poly count on my terrain from 7k->33k in order to get more smooth movement I need to walk across the terrain in my new First-Person-Shooter game. However, FPS(frames per second) is now an issue as you can imagine. I'm looking for an easy, simple solution, if it exists.

 

2r724o2.jpg

 

I'm aware of some techniques: 

 

(i) Frustum Culling: Never tried, but looks lengthy and difficult

 

(ii) Backface cull: I use 

glEnable(GL_CULL_FACE); glCullFace(GL_BACK); 
in my init, but I don't see any significant change in FPS.

 

(iii) LOD: I believe this only applies to terrain that is far away, which wouldn't be appropriate for my situation.

 

 

Any other solutions would be greatly appreciated.



Sponsor:

#2 SillyCow   Members   -  Reputation: 849

Like
0Likes
Like

Posted 30 June 2013 - 01:16 PM

What hardware are you using? On most modern machines (even phones) 33k faces should not be a big deal.

Are you using VBOs and FBOs?

 

If not, than this should be the first thing you do. A VBO + FBO are perfect for terrain because terrain does not move or change. If it's only 33k faces, then you can throw the entire thing in a single FBO (at least on a PC) and get lightning fast performance.

 

Also, it's 10 lines of code, so it's pretty simple.


My new android game : Enemies of the Crown

My previous android game : Killer Bees


#3 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 30 June 2013 - 01:26 PM

Geforce gtx 650 + i7 3770 (3.4ghz)

 

I'm actually using display lists for everything I draw. Are display lists deprecated? This is how I draw my terrain(inside a display list):

//draw terrain
for(int i=0;i<faces.size();i++){
     glBegin(GL_TRIANGLES);
         glColor4f(colors[faces[i]->colorNum-1]->r,colors[faces[i]->colorNum-1]->g,colors[faces[i]->colorNum-1]->b,1.0);
 
         glNormal3f(normals[faces[i]->faces[1]-1]->x,normals[faces[i]->faces[1]-1]->y,normals[faces[i]->faces[1]-1]->z);
         glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z);
 
         glNormal3f(normals[faces[i]->faces[3]-1]->x,normals[faces[i]->faces[3]-1]->y,normals[faces[i]->faces[3]-1]->z);
         glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z);
 
         glNormal3f(normals[faces[i]->faces[5]-1]->x,normals[faces[i]->faces[5]-1]->y,normals[faces[i]->faces[5]-1]->z);
         glVertex3f(vertex[faces[i]->faces[4]-1]->x,vertex[faces[i]->faces[4]-1]->y,vertex[faces[i]->faces[4]-1]->z);
    glEnd();
}

How would I transform these draw calls into a VBO/FBO?


Edited by Shawn619, 30 June 2013 - 01:39 PM.


#4 swiftcoder   Senior Moderators   -  Reputation: 9882

Like
0Likes
Like

Posted 30 June 2013 - 01:51 PM


I'm actually using display lists for everything I draw. Are display lists deprecated?

Yes. They are still reasonably performant though, as long as you are using them correctly.

 

This is how I draw my terrain(inside a display list):

To hit the performance path with display lists, you have to specify the same set of vertex attributes for every vertex.

 

You are missing that by only specifying the colour attribute once per face. You can see if repeating it for each vertex gives you a performance boost.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#5 SillyCow   Members   -  Reputation: 849

Like
0Likes
Like

Posted 30 June 2013 - 02:07 PM

VBOs and FBOs will be way more performant than display lists. Especially for terrain.

VBOs and FBOs are ideal for stuff that doesn't change (Terrain).

 

It basically means:

1. Put a big object on the video card

2. Draw that object

3. draw again

4. etc...

 

Notice that you only put the giant object on the video-card once. In GFX programming, the most expensive thing is telling your GFX card to do something. It's usually more expensive than what the card is actually supposed to do. So if you can give it as few commands as possible, you should see a great performance increase.

A display list consists of many commands per face which are repeated every frame.

 

In a VBO you write the "many commands" once when you configure your program. Then every time you redraw, you send the GFX card one single command (Draw what I sent you before).

 

Since there is one command per frame, your performance will sky-rocket.

 

Since you are using glbegin and glend, I am assuming that you are using openGL in "fixed pipeline" mode. That's great, because it's very simple.

Search the internet for a tutorial on VBOs.

 

Unfortunately, I've learnt this long ago (and in DirectX) so I cant point you to good & recent tutorial for openGL.

 

But here is a random one from the internet:http://sdickinson.com/wordpress/?p=122. If it is not easy enough, search for something else on the internet. VBOs today are quite common. The site that you originally learnt openGL from should have a VBO tutorial.

 

Learning VBOs, I was able to render a 50k face terrain without breaking a sweat on my Geforce 2 (in 2002). So your 650 should be able to do much much more.


Edited by SillyCow, 30 June 2013 - 02:14 PM.

My new android game : Enemies of the Crown

My previous android game : Killer Bees


#6 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 30 June 2013 - 02:11 PM

 


I'm actually using display lists for everything I draw. Are display lists deprecated?

Yes. They are still reasonably performant though, as long as you are using them correctly.

 

 

 

This is how I draw my terrain(inside a display list):

To hit the performance path with display lists, you have to specify the same set of vertex attributes for every vertex.

 

You are missing that by only specifying the colour attribute once per face. You can see if repeating it for each vertex gives you a performance boost.

 

Thanks for your replies.

 

I'm, not quite sure what you're saying, but i'm almost certain that I am using display lists correctly.

 

Yes, I think I will stick with display lists, for now at least.

 

I figured out the problem. My trees alone were 50k, and my grass alone was 44k, and removed both of these had no effect on FPS, so clearly an increased terrain polygons of 7k->33k isn't the problem.

 

The problem was with something completely different. Every frame I am doing a line-triangle intersection test on every terrain triangle to detection which polygon my character(camera) is currently sitting on, so that's why an increased terrain triangles from 7k-33k was such a big deal.

 

Can anyone recommend how I can reduce the number of line-triangle tests I need to do each frame? Because currently i'm at the worst possible solution, O(N) line-triangle comparisons, where N is the # of triangles in the terrain.



#7 swiftcoder   Senior Moderators   -  Reputation: 9882

Like
0Likes
Like

Posted 30 June 2013 - 02:21 PM


Can anyone recommend how I can reduce the number of line-triangle tests I need to do each frame? Because currently i'm at the worst possible solution, O(N) line-triangle comparisons, where N is the # of triangles in the terrain.

Your terrain is a height map, correct?

 

In that case, there is no need to do triangle intersection tests. You can calculate the intersection directly against the height map.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#8 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 30 June 2013 - 02:32 PM

 


Can anyone recommend how I can reduce the number of line-triangle tests I need to do each frame? Because currently i'm at the worst possible solution, O(N) line-triangle comparisons, where N is the # of triangles in the terrain.

Your terrain is a height map, correct?

 

In that case, there is no need to do triangle intersection tests. You can calculate the intersection directly against the height map.

 

 

No, not a height map. And please don't tell me to change my terrain to a height map.

 

It is a .obj model that is imported, then line-triangle tests are done on the imported triangles from the .obj model.



#9 swiftcoder   Senior Moderators   -  Reputation: 9882

Like
0Likes
Like

Posted 30 June 2013 - 03:07 PM


It is a .obj model that is imported, then line-triangle tests are done on the imported triangles from the .obj model.

In that case, you are out of luck.

 

General solution would be to provide a lower-resolution version of the mesh for collision detection.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#10 SillyCow   Members   -  Reputation: 849

Like
0Likes
Like

Posted 30 June 2013 - 03:17 PM

You could always use an octree,

That should make your intersection tests faster.

However, it is fairly complicated to implement.

 

But that is the standard "make my intersection tests quicker on an arbitrary mesh" solution.

 

If this is not a school project, you can probably grab an octree off the internet.

 

Hoever, if you can use a height map ,you'll have less work ahead for you.


My new android game : Enemies of the Crown

My previous android game : Killer Bees


#11 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 30 June 2013 - 03:30 PM

Thanks for your help guys, I really appreciate it!



#12 Shawn619   Members   -  Reputation: 342

Like
1Likes
Like

Posted 30 June 2013 - 05:00 PM

Update:

 

I randomly thought of a method that allows me to create a short list of faces to test intersection each frame, instead of testing all faces in the terrain(O(N)) on every frame.

 

With my method, I was able to narrow down the amount of intersection tests from the original 33000(all terrain faces) to ~100 each frame, which is quite manageable and resolved the FPS issue.

 

In computational complexity, I was able to reduce intersection tests from O(N)->O(sqrt(N)).


Edited by Shawn619, 30 June 2013 - 05:02 PM.


#13 Ameise   Members   -  Reputation: 714

Like
2Likes
Like

Posted 24 July 2013 - 05:51 PM

In other words, you implemented a O(log n) solution a la spatial subdivision?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS