200 trees = full CPU usage

I am trying to place trees on terrain.
I have 2 types of trees defined in egg files, each has 6 triangles, 1 tri with billboard effect and 5 with double-side rendering. and use instanceTo to duplicate.
when I have 200 trees , CPU rises to over 100%. I tried flattenStrong and RigidBodyCombiner, both gave no difference on performance.

I checked hierachy of the scene, each tree was inside RBC when I used RBC. strangely, the billboard effect still works while manual says it is not supported.
is that my fault in code or the manual is wrong?
(my code is on another PC, not connected to internet)

flattening was only for testing, as I want to move those trees in runtime. (flattenStrong returned 400 as result, my code should be correct.)
ps: it was called after I removed billboard attribute in egg files. with billboard they can’t be flattened. the act of removing billboard saved about 1/3 of CPU time though.

quantity 200 is too few, I want over 1000 at least.
my graphic card can draw 30000 triangles at 50fps at least, 200trees x 6 triangles should not be a problem. I wonder why RBC or flattening doesn’t help.

my CPU is pentium M 1.7g

The fact that CPU is used to 100% doesn’t mean anything. It just means that Panda3D is taking full advantage of your CPU. Anything less than 100% would be a waste.

If you don’t want Panda to use 100% of CPU, put time.sleep(0.001) in a task, or “client-sleep 0.001” in Config.prc.

As for the GPU, however, there are limits here. Most modern GPUs have trouble when you start asking them to render a few hundred meshes. You should flatten them together into groups to reduce the number of trees. (You may need to call clearModelNodes() on your tree model in order to be able to flatten different trees together).

If your trees don’t move, there’s no point in using the RigidBodyCombiner over flattening. It’s just added overhead.

thank you, clearmodelnodes (before flattening ) that you mentioned made a big difference. CPU time lowered from 66% to below 10%.

CPU time is important in my app, since I use my own function (using thread.sleep) to limit framerate, instead of the built-in clock limiter. time percentage is calculated by dividing task time by frame interval. other than task time, is sleep time. so if percentage is over 100, it means no sleep and task time is too long.

back to my problem, I want to use RBC because :
a) I want to move trees as the camera rotates or moves. so trees are reused, less memory consumption. now i’m not sure whether it is possible.
b) I want billboard on tree trunk so only 1 triangle is needed for the trunk (with help of alpha channel).

right now I know flattening allows me to have thousands of trees in view, but tree trunk can’t have billboard effect, and trees can’t move.
but without flattening, performance is too low.

problem remains, RBC doesn’t improve performance, why?
is there something similar to clearmodelnodes for RBC?

RBC doesn’t work with billboards. A billboard, by its very nature, requires the CPU to process each billboarded object individually–which means it can’t send all of the trees to the graphics card in one big burst (which is the point of both flattening and the RBC). So if you have billboarded each tree separately, it means you will send each tree to the graphics card separately, and this means you can’t have more than a few hundred trees.

Usually, when you want to get up into the thousands of something, you need something smarter than billboards. You can do this with a shader if you really want to (and you’re good with shaders), or you can model the tree dimensionally, so that billboards aren’t needed.

(Note that some old graphics tutorials recommend creating flat trees as billboards to save render time. This advice is no longer valid in the 21st century. Lots of polygons per tree are generally faster than a single billboarded flat per tree.)

David

thank you .
so I will use another approach.