Jump to content
  • Advertisement
Sign in to follow this  
jmakitalo

OpenGL Rendering many trees

This topic is 2269 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 have set up a system for rendering specifically trees, which are also generated by my engine. They are divided into basically two groups: trunk/branches and leaves. Both have their own index buffer and texture and they share the same vertex, normal etc. buffers. I decided to try instancing to speed up the OpenGL implementation, but I'm not sure if it will be much use, at least on its own. I have not yet implemented a level of detail, but want first to see how fast rendering can be with only quadtree culling and instancing. The tree instances are also sorted by textures and vertex buffers binds.

I have found that for some reason, rendering the trunk and branches is fast, but rendering the leaves is really slow. The leaves consist basically of triangle pairs, rendered with alpha testing (no blending) and with no face culling. In my test scene, I have 3000 trees, which are frustum culled to less than 1/4. The trunk/branches consist of 2166 indices and the leaves consist of 582 indices. When rendering only the trunk/branches, FPS can be around 60, whereas rendering the leaves only yields around 20 FPS. See the images below:

http://www.perilouspenguin.com/glfps/wp-content/uploads/2012/05/full.jpg
http://www.perilouspenguin.com/glfps/wp-content/uploads/2012/05/leaves.jpg
http://www.perilouspenguin.com/glfps/wp-content/uploads/2012/05/trunks.jpg

First I was thinking that it might be a fillrate problem, as the leaves clearly occupy more screen space. But turning the camera away from the leaves does not seem to make any practical difference. Could this have to do with how indexing or vertex data placement works out for the branches and the leaves? For the branches, a single vertex is referenced around 5 times, whereas for the leaves, only 1 or 2 times. Still, there are a lot less vertices in total for the leaves in the test scene.

I understand that LOD could make all the difference in the end, but I have also tried to reduce the number of leaves, and it does not seem to make a big difference. Even a small amount of leaves per tree seems to kill the frame rate pretty good.

Share this post


Link to post
Share on other sites
Advertisement
Are you using mip-maps for your leaves texture ?

If not, you may speed up things by doing so, and also potentially reduce your aliasing. Edited by (ok)

Share this post


Link to post
Share on other sites

Are you using mip-maps for your leaves texture ?

If not, you may speed up things by doing so, and also potentially reduce your aliasing.


Yes, I'm using mip-maps.

Share this post


Link to post
Share on other sites
Are you using frustum culling ?
If yes, I don't understand why your fps still stalls even if the camera is not facing the leaves.

What is the size of your leave texture ?
Did you try to load a really low one (eg. 1*1) to see if the problem comes from here ?

Share this post


Link to post
Share on other sites
Ooops sorry, you are doing quadtree culling yet so there might be unnecessary traversal.
My best guess is to debug your quadtree scheme and make sure no unnecessary trees are processed before or after.

Share this post


Link to post
Share on other sites

My best guess is to debug your quadtree scheme and make sure no unnecessary trees are processed before or after.


Actually the quadtree frustum culling is so simple, that it only considers a 2D view frustum, which is independent of the camera pitch. I know that this does not work correctly for all cases, but it is fast and works in most cases. The point being now that it does not change the amount of trees processed, if the camera faces the ground. I have also tried low-resolution texture for the leaves with no improvement.

Share this post


Link to post
Share on other sites
Ok so it is not the drawing...

I don't know how you have implemented your quadtree but maybe you could test if some trees located outside the desired area get processed ?

For example, you could try to setup a breakpoint if a candidate tree is outside the desired area just to check. You could also double check if your whole loop or part of it does not get processed several time instead of only once. Check if one of your visible trees does not get considered more than once.

It happens to me all the time, fast(your [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]trunk/branches[/background]

[/font]) does unfortunately not always mean neat.

Good luck.

Share this post


Link to post
Share on other sites
The general steps go roughly like this:

First thing to answer is if the slowdown caused by being CPU-bound or GPU-bound? (or, in very rare cases, bad sequential structure causing both CPU and GPU -bound?)
Use tools like AMD CodeAnalyst, Intel vTune, nVidia Parallel NSight, nVidia PerfHUD, Intel GPA, custom intrusive profiling blocks (Game Programming Gems 1), to profile the CPU and GPU workloads.


If you are CPU bound:
- Identify where the additional CPU time is spent. If it is directly in your code, optimize it.

- If the time is spent inside the graphics driver dll, identify how to reduce draw call count by batching. Group vertex buffers together and atlas textures to achieve this.

If you are GPU bound:
- Look at the GPU instruction call trace to identify if you can optimize redundant state sets.
- Identify whether you are vertex shader, pixel shader, texture load, or framebuffer raster op bound. Optimize the appropriate stages or reduce the workload.

I suspect you are somehow CPU bound, since you say that adding rendering workload that is outside the view frustum still causes slowdown.

Share this post


Link to post
Share on other sites
As disabling the leaves does not affect quadtree and increases performance a lot, I dont believe that the quadtree is the problem. I could still double check.

I have not tried to sort the leaves by distance, but I did try sorting the tree objects, after the frustum culling. Did not help either, though I'm not sure how efficient my sorting procedure was (used the stl algorithm to sort the vector of indices to visible trees).

I have never used any actual performance measurement tools, though maybe they would prove useful. Probably takes some time to learn how to use them. Are there any versions for Linux?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!