Rendering many trees
#1 Members - Reputation: 331
Posted 27 May 2012 - 09:39 AM
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.
#4 Members - Reputation: 104
Posted 27 May 2012 - 10:16 AM
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 ?
#6 Members - Reputation: 331
Posted 27 May 2012 - 10:57 AM
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.
#7 Members - Reputation: 104
Posted 27 May 2012 - 11:10 AM
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
trunk/branches
) does unfortunately not always mean neat.Good luck.
#9 Members - Reputation: 1587
Posted 27 May 2012 - 11:29 AM
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.
#10 Members - Reputation: 331
Posted 27 May 2012 - 12:32 PM
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?
#11 Members - Reputation: 104
Posted 27 May 2012 - 02:03 PM
You will be glad to simply check out methods with the highest profiles(the ones on top of the list) and possibly concentrate on/optimize them.
You can also more directly evaluate the time spent between statements with very simple functions.
Just google for c++ profiler/profiling tools.
Bench-marking your code is crucial to evaluate yet if you have enough budget for a specific job before writing it.
It also helps a lot to get extra clues about what's possibly wrong.
#12 Members - Reputation: 331
Posted 27 May 2012 - 02:29 PM
I'm not sure if this is related, but I have also found that if I have, say, just one mesh that represents e.g. a hedge, consisting of maybe twenty crossing planes with alpha tested semi-transparent texture with opaque and transparent parts alternating at small scale, then a closeup view will make the rendering to crawl. Why would this happen? I mean, I understand that a large alpha blended polygon would have a large impact, but why alpha tested?
#13 Members - Reputation: 104
Posted 27 May 2012 - 03:03 PM
Sometimes it is hard to figure out the cause of your stalls from the profiler only but if a module function comes on top at your app's run-time, at least you know your app is intensively using it. You must also use timing functions directly in your code to locate bottlenecks.but usually the data seems useless
For your second question, it often depend on your transparency approach. If you use raw blending, you need a clever primitive ordering to get the most of it but sometimes screen door is more appropriate (no back to front order needed).
Check those :
http://www.gamedev.net/topic/599103-issues-with-blending-transparency/
http://www.opengl.org/archives/resources/faq/technical/transparency.htm
#14 Members - Reputation: 331
Posted 28 May 2012 - 11:03 AM
#15 Members - Reputation: 331
Posted 28 May 2012 - 01:29 PM
#17 Members - Reputation: 331
Posted 28 May 2012 - 02:54 PM
#20 Members - Reputation: 331
Posted 29 May 2012 - 08:20 AM
Try to use alpha to coverage, it´s realy fast and could get you a extra fps.
What do you mean by using alpha? I use alpha testing, which I believe is cheap, but it still yields low framerates.
I also just realized that there is the "discard" function in fragment shaders. I think that this improved the situation slightly, but it's not doing wonders.
Only other thing I can think of is impostors, which can look very good if done right - Oblivion (SpeedTree) faded the tree model out for a flat billboard as close as 50m from the camera, and the treescapes always looked great (imo)
Perhaps this is one way, but I bet it is a fair amount of work to make it fast and still look good. Probably need some fancy texture atlasing and what not.
Occlusion query might help to reduce the overdraw, but I'm suspicous as the meshes are quite low-poly and there are many of them.
Ok so, it is established that the low fps is obtained when the trees are in the view frustum and fill most of the screen. Can one deduce from this, that
the program is limited by fillrate or can there be some more complicated caching between vertex and pixel processing, so that the number of polygons
could still matter?
How do games generally cope with the problem, that if you have e.g. a hedge or a bush consisting of a few hundred overlapping alpha tested polygons and the player goes very
close to this bush? This really seems to crush the framerate even without alpha blending. Is the only way to improve the framerate just to do a precise depth sort from front to back?






