diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index d4429bfcb..f6c681d78 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -890,17 +890,46 @@ void* PhysicsBackend::CreateScene(const PhysicsSettings& settings) sceneDesc.gravity = C2P(settings.DefaultGravity); sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVE_ACTORS; if (!settings.DisableCCD) - sceneDesc.flags |= PxSceneFlag::eENABLE_CCD; + sceneDesc.flags |= PxSceneFlag::eENABLE_CCD | PxSceneFlag::eENABLE_PCM; sceneDesc.simulationEventCallback = &scenePhysX->EventsCallback; sceneDesc.filterShader = FilterShader; sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity; - sceneDesc.solverType = PxSolverType::ePGS; + + switch (settings.SolverType) + { + case PhysicsSolverType::ProjectedGaussSeidelIterativeSolver: + sceneDesc.solverType = PxSolverType::ePGS; + break; + case PhysicsSolverType::DefaultTemporalGaussSeidelSolver: + sceneDesc.solverType = PxSolverType::eTGS; + break; + default: ; + } + + sceneDesc.solverType = PxSolverType::eTGS; if (sceneDesc.cpuDispatcher == nullptr) { scenePhysX->CpuDispatcher = PxDefaultCpuDispatcherCreate(Math::Clamp(Platform::GetCPUInfo().ProcessorCoreCount - 1, 1, 4)); CHECK_INIT(scenePhysX->CpuDispatcher, "PxDefaultCpuDispatcherCreate failed!"); sceneDesc.cpuDispatcher = scenePhysX->CpuDispatcher; } + + switch (settings.BroadPhaseType) + { + case PhysicsBroadPhaseType::SweepAndPrune: + sceneDesc.broadPhaseType = PxBroadPhaseType::eSAP; + break; + case PhysicsBroadPhaseType::MultiboxPruning: + sceneDesc.broadPhaseType = PxBroadPhaseType::eMBP; + break; + case PhysicsBroadPhaseType::AutomaticBoxPruning: + sceneDesc.broadPhaseType = PxBroadPhaseType::eABP; + break; + case PhysicsBroadPhaseType::ParallelAutomaticBoxPruning: + sceneDesc.broadPhaseType = PxBroadPhaseType::ePABP; + break; + default: ; + } // Create scene scenePhysX->Scene = PhysX->createScene(sceneDesc); diff --git a/Source/Engine/Physics/PhysicsSettings.h b/Source/Engine/Physics/PhysicsSettings.h index 1533665e8..8fa2a7295 100644 --- a/Source/Engine/Physics/PhysicsSettings.h +++ b/Source/Engine/Physics/PhysicsSettings.h @@ -6,6 +6,50 @@ #include "Engine/Core/Math/Vector3.h" #include "Types.h" +/// +/// Broad phase algorithm used in the simulation. +/// +/// +API_ENUM() enum class PhysicsBroadPhaseType +{ + /// + /// Sweep and prune. + /// + SweepAndPrune = 0, + + /// + /// Multi box pruning. + /// + MultiboxPruning = 1, + + /// + /// Automatic box pruning. + /// + AutomaticBoxPruning = 2, + + /// + /// Parallel automatic box pruning. + /// + ParallelAutomaticBoxPruning = 3, +}; + +/// +/// The type of solver used in the simulation. +/// +/// +API_ENUM() enum class PhysicsSolverType +{ + /// + /// Projected Gauss-Seidel iterative solver. + /// + ProjectedGaussSeidelIterativeSolver = 0, + + /// + /// Default Temporal Gauss-Seidel solver. + /// + DefaultTemporalGaussSeidelSolver = 1, +}; + /// /// Physics simulation settings container. /// @@ -43,6 +87,18 @@ public: API_FIELD(Attributes="EditorOrder(70), EditorDisplay(\"Simulation\")") bool DisableCCD = false; + /// + /// Broad phase algorithm to use in the simulation. + /// + API_FIELD(Attributes="EditorOrder(71), EditorDisplay(\"Simulation\")") + PhysicsBroadPhaseType BroadPhaseType = PhysicsBroadPhaseType::SweepAndPrune; + + /// + /// The solver type to use in the simulation. + /// + API_FIELD(Attributes="EditorOrder(72), EditorDisplay(\"Simulation\")") + PhysicsSolverType SolverType = PhysicsSolverType::ProjectedGaussSeidelIterativeSolver; + /// /// The maximum allowed delta time (in seconds) for the physics simulation step. ///