PhysX tip: make sure debug visualization is really disabled
In PhysX, debug visualization is enabled or disabled by this call:
PxScene::setVisualizationParameter(PxVisualizationParameter::eSCALE, Value);
With Value = 0.0 to disable it, and usually Value = 1.0 to enable it (but any non-zero value will enable it, and then be used as a scale factor for normals, etc).
Simply setting the PxVisualizationParameter::eSCALE to 1.0 does not render anything on its own. Users have to enable additional flags to tell the system which debug gizmos they want to see. For example here is the list I use in PEEL (but there’s more in the SDK):
- PxVisualizationParameter::eSCALE,
- PxVisualizationParameter::eBODY_AXES,
- PxVisualizationParameter::eBODY_MASS_AXES,
- PxVisualizationParameter::eBODY_LIN_VELOCITY,
- PxVisualizationParameter::eBODY_ANG_VELOCITY,
- PxVisualizationParameter::eCONTACT_POINT,
- PxVisualizationParameter::eCONTACT_NORMAL,
- PxVisualizationParameter::eACTOR_AXES,
- PxVisualizationParameter::eCOLLISION_AABBS,
- PxVisualizationParameter::eCOLLISION_SHAPES,
- PxVisualizationParameter::eCOLLISION_AXES,
- PxVisualizationParameter::eCOLLISION_COMPOUNDS,
- PxVisualizationParameter::eCOLLISION_FNORMALS,
- PxVisualizationParameter::eCOLLISION_EDGES,
- PxVisualizationParameter::eCOLLISION_STATIC,
- PxVisualizationParameter::eCOLLISION_DYNAMIC,
- PxVisualizationParameter::eJOINT_LOCAL_FRAMES,
- PxVisualizationParameter::eJOINT_LIMITS,
- PxVisualizationParameter::eMBP_REGIONS,
Now there is a trap here.
The trap is that if you just set PxVisualizationParameter::eSCALE to 1.0 alone, nothing gets rendered but it still has a performance impact. And it can be invisible to users, until they use a profiler.
For example in PEEL, it means that this particular UI config has a clear negative impact on performance:
And here’s the effect on performance in “ConvexGalore2″:
As you can see this is quite significant. The drop on the blue curve corresponds to the moment I unchecked “Enable debug visualization” in the UI. As soon as I did, performance went back to normal.
So, be aware of this, and make sure you don’t ship your game with PxVisualizationParameter::eSCALE still set to 1.0.