PStats Cull

Hi there,
I am just working on performance tuning for my project and most of its time is spend claculating physics (NxPanda) anyway but I also noticed quite a lot of time spend in Cull if there are many objects in view. E.g. for 50 little rocks it rises from 0.5 to 3.5 ms, with 100 to 7.3. As soon as these objects are not in view anymore it drops down to 0.5 agian.
Can anyone tell me what exactly is calculated in Cull? Is it just the culling with the frustum of the camera or is there anything more? And why does it take so much more time if there are lots of objects in view?

thanks
felix

“Cull” is not just the time spent performing view-frustum culling; it includes the time to traverse the scene graph, accumulate state and transforms, and generally prepare geometry to be sent to the graphics card.

Cull tends to be heavy when there are lots of nodes visible. If you have 50 little rocks, and each rock is its own node, that’s probably too many nodes. It’s better to combine multiple rocks into a single node where possible. This will reduce both Draw and Cull times.

Panda can do this for you automatically. Try calling root.flattenMedium() or root.flattenStrong(), where root is a NodePath on the top of your scene.

David

Hmm, sorry if I maybe interrupt the topic, but reading your reply I have a question:

Does it really need to be at the top of the scene? Because I had experiences in the past where flattenStrong did not flatten correctly, I thought this was a bug, but that might be related to this? Or am I reading this wrong?

Hi David,
thanks for the quick answer. I hope you don’t mind that it triggers some more questions from me :slight_smile:
It is true I had each rock as a seperate node parented to render because these are free moving rocks. But on top of that each rock (which is partly hollow -> transparent) has a hole inside and there’s some glow in there. This glow is a plane with a texture (partly transparent again) and is also on a seperate node parented to render. Quite inefficient I guess. So I tried two things:

First - because I supsected it is good to group all objects that have the same materials (color, shader, transpareny, …) to reduce state changes - I made one nodepath (parented to render) for the rocks that has the shader and texture set and parented all rocks to this. Then I made another nodepath (again parented to render) with texture, transparency set, etc. for the glow and parented each glow plane to this. This didn’t get me any different cull time.

Second I tried making a root nodepath for each rock and parenting the nodepath for the rock model as well as the nodepath for the glow to it. So each rock had a nodepath parented to render and to this nodepath a nodepath for the model and one for the glow are parented. This also didn’t change anything with the culling time.

So obviously I don’t really understand what could reduce these culling times. Should I try to group rocks that are closer together under one nodepath? The problem is that the player is able to freely move these indivdual rocks around so they most likely wont stick close to each other. Or is the culling problem not connected to the position of the rocks? Or is the extra glowing texture just expensive and there is not much I can do about it.

It’s just number of nodes. flattenMedium() and flattenStrong() will both remove nodes, which is the whole point. It doesn’t matter whether you separate out the glows or not; they can be mixed in with the rocks and flattenStrong() can still pull them out.

You can call flatten on any node, it doesn’t have to be the root of your scene. It depends on how much you want to flatten at a time. I’m not aware of any bugs in flatten.

David