From Physics Simulation Wiki
Advanced constraint solver settings
The Bullet constraint solver can be customized and configured using the advanced settings in the btContactSolverInfo structure.
Access to btContactSolverInfo
btContactSolverInfo& info = dynamicsWorld->getSolverInfo();
By default, Bullet uses the the Projected Gauss Seidel constraint solver for contact and joint constraints. This is an iterative LCP solver, informally also described as 'sequential impulse' by Erin Catto. A reasonable range of iterations is from 4 (low quality, good performance) to 20 (good quality, less but still reasonable performance), while the default is 10.
btContactSolverInfo& info = dynamicsWorld->getSolverInfo(); info.m_numIterations = 20;
The PGS constraint solver has several features that can be controlled by the 'm_solverMode' setting.
By default, only the warmstarting and SIMD is enabled.
- SOLVER_USE_WARMSTARTING : The PGS is an iterative algorithm where each iteration is based on the solution of previous iteration. If no warmstarting is used, the initial solution for PGS is set to zero each frame. When using warmstarting, the first iteration uses the last solution of the previous frame. This improves convergence towards a better solution and hence stacking stability.
- SOLVER_RANDMIZE_ORDER : the PGS solver solves constraints one constraint row at a time. By randomizing the order of solving the constraint rows, stacking stability can be improved (at the cost of a little bit of performance)
- SOLVER_SIMD : use a SSE optimized innerloop, using assembly intrinsics. This is implemented and can be enabled/disabled for Windows and Mac OSX versions, single-precision floating point, 32bit.
Todo: explain meaning etc.
- SOLVER_USE_FRICTION_WARMSTARTING = 8,
- SOLVER_USE_2_FRICTION_DIRECTIONS = 16,
- SOLVER_ENABLE_FRICTION_DIRECTION_CACHING = 32,
- SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION = 64,
Obsolete Solver Mode settings
- SOLVER_CACHE_FRIENDLY : obsolete
- SOLVER_CUDA : obsolete setting, we implemented an experimental constraint solver for CUDA. We plan a more GPU friendly physics pipeline for Bullet 3.x, using OpenCL.
By default, Bullet solves positional constraints and velocity constraints coupled together. This works well in many cases, but the error reduction of position coupled to velocity introduces extra energy (noticeable as 'bounce'). Instead of coupled positional and velocity constraint solving, the two can be solved separately using the 'split impulse' option. This means that recovering from deep penetrations doesn't add any velocity. You can enable the option using:
btContactSolverInfo& info = dynamicsWorld->getSolverInfo(); info.m_splitImpulse = 1; //enable split impulse feature //optionally set the m_splitImpulsePenetrationThreshold (only used when m_splitImpulse is enabled) //only enable split impulse position correction when the penetration is deeper than this m_splitImpulsePenetrationThreshold, otherwise use the regular velocity/position constraint coupling (Baumgarte). info.m_splitImpulsePenetrationThreshold = -0.02;
Although this removes most of the extra energy/bounce, it degenerates quality a little bit, in particular for stable stacking. Hence, the setting is disabled by default. Also note that the split impulse option is only enabled for contact constraints, and none of the other joints (hinge/ball socket and so on), for quality reasons.
Resting contact restitution threshold
By default, Bullet implements a mechanism for resting contacts to improve stability, by setting the restitution to zero. It compares the contact lifetime using a threshold, to determine 'resting' contact. You can control this threshold or disable it using the following code snippet:
btContactSolverInfo& info = dynamicsWorld->getSolverInfo(); info.m_restingContactRestitutionThreshold = 1e30;
Undocumented members of btContactSolverInfo
Several of those fields are undocumented or used internally (such as 'm_timeStep').
btScalar m_tau; btScalar m_damping; btScalar m_friction; btScalar m_timeStep; btScalar m_restitution; btScalar m_maxErrorReduction; btScalar m_sor; btScalar m_erp;//used as Baumgarte factor btScalar m_erp2;//used in Split Impulse btScalar m_globalCfm;//constraint force mixing btScalar m_linearSlop; btScalar m_warmstartingFactor; int m_solverMode;