Sign in to follow this  

Raising 3D Game Frame rate

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I made a 3d game/engine, and it is currently displaying maybe 7-9k polygons. My frame rate is really bad, dipping down as low as 10 fps. I am trying to find some ways of techniques to raise my frame rate. I am using 256x256 textures, and i tried reducing them all to 128x128, and that bumped it up to about 15 fps at the lowest. Are textures the biggest source of rendering lag? what is the normal resolution for textures? Are there any setings i could do like face culling that would help? and how much would it help. I have noticed in games how they cut corners to lower the FPS, like not displaying "extra scenery" like barrels unless you are pretty close, like in Half Life 2. Does this help a lot? Also, does the size of the polygon effect the rendering time? I am using OpenGL if that matters. Obviously in the top end games they are displaying tons more polygons than I am, so i must be doing something really wrong. Any ideas or comments on this subject would be greatly appreciated. I want to at least double my fps, so i can add more stuff with out slowing the computer to a hault, thx.

Share this post


Link to post
Share on other sites
Modern games might use 7k-9k triangles on a single model, and have up to 500k triangles in a scene... so yeah, assuming you have a new-ish gfx card, you can definately improve your FPS.

My guess would be that you're rendering your triangles using old, CPU-powered draw methods (e.g. glVertex3f calls).

If this is the case, look into indexed meshes and triangle strips (techniques to reduce the overall size of your mesh data), and vertex buffer objects (a technique to store your mesh in video RAM, so that the CPU doesn't have to transfer the data from system RAM every frame).

Share this post


Link to post
Share on other sites
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot. It is worth to implement. Textures of 256x256 are ok. Also calling object render functions lot of times is LOT SLOWER than batching objects and render them in one or two calls.
There is one good engine that was made from good idea and batch a lot. It is Cube Engine. It is made in OpenGl so I think you can learn something from it (it is open source [smile]),

Share this post


Link to post
Share on other sites
Quote:
Original post by streamer
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot.


does glEnable(GL_CULL_FACE); do this sufficiently? or should i write my own.



Quote:
Original post by Adam_42
1. Are you using mip mapping?
2. How many textures are you using? Are you running low on video ram?

Also what graphics card are you using?


This is not a problem on just my computer, I have tested my game on 4 different ones, and it is slow on all of them. This is more about properly coding it than my computer sucking(which it REALLY does :( ).



Quote:
Original post by Hodgman
Modern games might use 7k-9k triangles on a single model, and have up to 500k triangles in a scene... so yeah, assuming you have a new-ish gfx card, you can definately improve your FPS.

My guess would be that you're rendering your triangles using old, CPU-powered draw methods (e.g. glVertex3f calls).


Wow, i didnt realize how low polygons i actually have. Yes I am using glVertex3f, but that is because I load and run my 3d models in the same format that they are in the .obj file. I am rebinding the texture and making a new GL_triangle this for each triangle in the model, which I am guessing now is a REALLY slow thing to do. Should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

EDIT: I fixed so it only binds the texture once for each model, and the fps on my comp raised form 1 to 5!(Im on a windows 98 computer, so the important fact is that it raised so much, not that it is 5 lmao, yes i need i new comp). Keep the tips coming, thx!


I am set on making my own engine for the game, so I want to learn how to do all of this stuff. I will google all the stuff you guys have suggested.

Some more question:
-Is there a rendering difference between different shapes, like gl_polygon, gl_trinagles, gl_quads?
-What is the normal frame rate for games? Ive heard 60, is that good enough?

Thx for all of the posts! I really appreciate it.

[Edited by - bovinedragon on October 2, 2007 8:28:12 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by bovinedragon
Yes I am using glVertex3f

You can replace all of your glVertex3f calls by using VBO's (assuming your graphics card supports this feature).

glVertex is slow, because it requries the CPU to do a lot of work constructing the mesh every frame, and has to transfer this mesh data from RAM to the video card every frame. If you use a VBO, then the CPU hardly has to do a thing, and there is no transfer from RAM anymore.

Quote:
should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

NVidia provides a free library that can do this for you on the fly, called NVTriStrip. I'm not sure how hard it is to use though - the amount of effort it might take you to use this library might not pay off in a big FPS improvement.

Quote:
-Is there a rendering difference between different shapes, like gl_polygon, gl_trinagles, gl_quads?

If you use quads/polies, then the driver will automatically convert your quads/polygons into triangles on the fly, which is slow. You should always use triangles, lines or points.

Quote:
-What is the normal frame rate for games? Ive heard 60, is that good enough?

Anything above 24fps is good enough, 30fps is average, 60fps is great.

Share this post


Link to post
Share on other sites
Quote:
Original post by bovinedragon
Quote:
Original post by streamer
And I also read somewhere that "you can really render objects fast, if you don't render them at all". So if you don't need to render something (like wall behind your back) then don't render it. That is culling, and it helps you a lot.


does glEnable(GL_CULL_FACE); do this sufficiently? or should i write my own.

for a 7-9k poly scene this is good enough. When you have more models / polygons on screen look into frustum culling, which will stop every model that won't be on the screen from being rendered.


Quote:

I am rebinding the texture and making a new GL_triangle this for each triangle in the model, which I am guessing now is a REALLY slow thing to do. Should i write some way to organize the triangles so that they could be used with a triangle strip, and is there some better file format than .obj that mignt do some of this for me?

1. If you can already load .obj files, then stick with them for now.
2. Don't call glBegin() for every triangle ! This might be the biggest slow-down in your code at the moment. Do it once for each model, like the the texture binding, and then just call glVertex* as often as you have to.
3. As you already have the triangle and vertex information, putting all that in a vertex array once intead of drawing it should be pretty straight forward.
4. When you have a vertex array using a VBO to upload it to video memory is only a little more work.
5. Then you can remove all duplicate vertices from your vertex array and build an index buffer to go allong with the vertex buffer, which will save some memory and might give another speed increase.
6. Optimize vertex/index order to utilize the vertex cache as good as possible. I think both ATi and NVIDIA have tools for this on their homepages.

Share this post


Link to post
Share on other sites
Just because you are loading obj files it doesnt mean that you cant use glDrawArrays or glDrawElements in OpenGL or VBO's. When you are loading an obj just construct the structure in such a way that you can send the data in one go during a render call for each model using glDrawArrays or glDrawElements. If you can manage that then you can easily modify the code to use VBO's. That should probably give you a major framerate boost from glVertex3f calls.

Coming to OpenGL culling, you want to reduce the amount of data you are sending down the card before the driver does that work for you so do it on a high level basis once and then let the card do it for more finer based culling. But only worry about that when you get to more triangles than what you currently have. For the number of triangles you have OpenGL culling should work just fine.

Share this post


Link to post
Share on other sites
the most important thing is to find out whats causing the lack of speed or else youre just blindly stabbing in the dark wasting time/effort, it could be one of 100 things, amd/nvidia websites have pdf's on help on finding an apps bottlenecks. once u know whats causing the problem then u can solve it

eg download this pdf

http://72.14.253.104/search?q=cache:0MSvD5y2TH4J:ati.amd.com/developer/gdc/GDC2005_OpenGL_Performance.pdf+gdc2005_opengl_performance&hl=en&ct=clnk&cd=1&client=firefox-a

Share this post


Link to post
Share on other sites
Quote:
Original post by CRACK123
Just because you are loading obj files it doesnt mean that you cant use glDrawArrays or glDrawElements in OpenGL or VBO's. When you are loading an obj just construct the structure in such a way that you can send the data in one go during a render call for each model using glDrawArrays or glDrawElements. If you can manage that then you can easily modify the code to use VBO's. That should probably give you a major framerate boost from glVertex3f calls.


Is the format of the structures on the NeHe tutorial the only way that they can be set up to be loaded into the VBO? The way that they load data into a vertex array(inm looking at this site: http://www.songho.ca/opengl/gl_vertexarray.html) is a lot like how i have my data set up now. Can i use the vertex array structure to load it into a VBO? or do i have to format it like the NeHe tutorial? I am using vectors too, does that make a difference than arrays, which is what NeHe uses.

also, when i use glEnable(GL_CULL_FACE);, it mostly works, but makes most of my walls not appear. How does this calculate what is the front and back of the face?

Also i made a counter, and turns out i am using 19k triangles if that matters

[Edited by - bovinedragon on October 3, 2007 9:15:07 PM]

Share this post


Link to post
Share on other sites
u have not found out whats causing the bottleneck

19,000 tris is nothing for todays cpu's even for immediate mode, ie u will implememnt VBOs + then come back in 2 days time + say it doesnt help :) (though using VAs is always good)

so i repeat

the most important thing is to find out whats causing the lack of speed or else youre just blindly stabbing in the dark wasting time/effort, it could be one of 100 things, amd/nvidia websites have pdf's on help on finding an apps bottlenecks. once u know whats causing the problem then u can solve it

eg download this pdf

http://72.14.253.104/search?q=cache:0MSvD5y2TH4J:ati.amd.com/developer/gdc/GDC2005_OpenGL_Performance.pdf+gdc2005_opengl_performance&hl=en&ct=clnk&cd=1&client=firefox-a



Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
u have not found out whats causing the bottleneck


Yeah thx for the link, i will look into it and post what I find. I will try VBO just cuz I should do that anyway.

EDIT:
ok i read the pdf, and this is what I came up with

I tested on crappy comp, probably isnt the best place to test it.

Change with resolution, changes up to 1 FPS , so not Pixel bottleneck?

Turning off Lighting, raised FPS from 5 to ~6.5, not really Vertex bottleneck?

Reducing rendered triangles by 1/2, raised FPS from 5 to ~8.5, Submission/fetch bottleneck, this is what VBO fixes right?

"CPU Bottlenec: Find API versus application time" - What does this mean?

Also, i wrote a simple frustrum culling function, and If I stand face away from most of my scene, I can reduce it from 19k triangles to ~6k and my FPS jumps from 5 to ~25!! What type of bottleneck would this classify as?


[Edited by - bovinedragon on October 4, 2007 6:15:40 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by bovinedragon
Also, i wrote a simple frustrum culling function, and If I stand face away from most of my scene, I can reduce it from 19k triangles to ~6k and my FPS jumps from 5 to ~25!! What type of bottleneck would this classify as?


Your culling algorithm is reducing the number of triangles submitted to the API by ~1/3 so it's a "Submission/fetch bottleneck".
Culling will reduce the "submission" times, and VBOs should reduce the "fetch" times, so implementing VBO's and a decent culling algorithm should fix most of your problems (hopefully) ;)

Quote:
Original post by bovinedragon
"CPU Bottlenec: Find API versus application time" - What does this mean?

If you start/stop a timer before/after any openGL function calls, and add up all these time values for each frame, then you can find out what percentage of time in each frame is being spent inside the OpenGL API compared to the amount of time spent executing your own code.
For example, if you were doing lots of Physics or AI in your code, then that could be to blame for the lousy FPS, not the graphics at all. In this kind of situation you might find that each frame takes 20ms, but only 1ms is spent inside the graphics API.

Share this post


Link to post
Share on other sites
your framerate sounds suspiciously low perhaps u dont have hardware acceleration
try
cout << glGetString( GL_VENDOR ) << glGetString( GL_RENDERER ) << endl;

whats your cpu/graphics card?
have u tested other ppls apps?

though even if its software, changing resolution should show a huge difference

are u testing between 2 completely different sizes eg 320x240 + 1024x768 (+ not say 1024x768 + 800x600)

possibly u are going
for ( i=0; i<19000; i++ )
{
glBegin( GL_TRIANGLE );
glVertex3fv(a); glVertex3fv(c); glVertex3fv(c);
glEnd();
}

if so u need to do

glBegin( GL_TRIANGLE );
for ( i=0; i<19000; i++ )
{
glVertex3fv(a); glVertex3fv(c); glVertex3fv(c);
}
glEnd();

Share this post


Link to post
Share on other sites
Quote:
I am rebinding the texture and making a new GL_triangle this for each triangle in the model,


you should bind your texture only once... something like this:

BindTexture2D(...)
glBegin(GL_TRIANGLES);
for (i=0;i<numTriangles;i++)
{
glVertex3f(...);
}
glEnd();

make sure the loop doesn't include texture binding or glEnable calls, they are very slow when put in a loop

Share this post


Link to post
Share on other sites

This topic is 3719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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