UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
编程
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes

Physics Optimization

Computation of physical interactions can be very demanding. There are optimization techniques providing high performance and overall stability for your interactive projects.

Common Settings#

Keep the global physics settings at a reasonable demanding level.

Notice
To configure physics settings, open the Settings window by choosing Window -> Settings in the main menu and select Runtime -> World -> Physics section.

  • Specify the Distance from the camera, from which physical interactions will not be calculated. If a physics-based node exceeds this limit, it will freeze and its physical calculations will be skipped until the node gets closer to the camera.

    Cloth simulation halts starting from the specified distance from the camera.

    Notice
    Cloth, Rope and Water physical bodies have their own Simulation Distance parameter as well.
  • The Iterations parameter is capable of increasing stability, but also resulting in a higher load. High number of iterations may lead to noticeable lags as very time-consuming calculations are automatically skipped. One physics iteration is quite enough for simple scenes.

  • Adjust the time Budget for Physics simulation.

Collision Detection Optimization#

Filtering Interactions#

It is very unlikely that each physics-based object in your project will interact with all the other ones. It will rather have several groups of related objects dedicated to certain tasks.

Having multiple objects taking part in physical simulation, you should divide the ones, which are hardly going to interact with each other, into different "groups" by using the Bit Masking mechanism.

Limiting Collisions#

Set matching Collision Masks for those particular shapes, surfaces and bodies that are expected to collide. If the masks do not match, shapes and bodies will simply ignore each other by going through.

Collisions are calculated for a plane and a sphere while a box is ignored due to unmatching Collision Masks.
The Collision Mask of the sphere's physical shape.
The Collision Mask of the box's physical shape.
The Collision Mask of the plane's surface.
The Collision Mask of the ground's surface.

Unigine allows setting up filtering precisely by using the Exclusion Mask. It allows ignoring shapes with the matching exclusion mask regardless of their Collision Masks.

Surfaces which are not intended for physical interactions should have the Collision flag disabled. For example, a dashboard inside a cockpit would never take part in collision detection on the outside.

It is a basic way to lighten physical calculations by avoiding detection of undesired and unnecessary collisions.

Filtering Physical Effects#

Specify certain physicals that should affect only corresponding bodies by using the Physical Masks the same way as for collisions. On the image below, a Physical Wind object affects a cloth banner but not a sphere.

A physical wind affects a cloth but not a sphere.
Physical mask of the cloth banner.
Physical mask of the sphere.
Physical mask of the Physical Wind object.
Physical mask of the Physical Wind object.

Intersection Mask#

Intersection is a generic point of a specified area (or line) and an object. Calculation of intersection between a ray cast and a surface is fast and inexpensive and therefore sometimes can be used instead of computing collision. For example, calculation of collisions of car wheels with the ground can be simplified by using intersections.

Although it is a programmatic approach only, it requires Intersection Masks to be set for filtering purposes.

Both physical shapes and surfaces have intersection masks.

Reducing colliders complexity#

As a rule, most 3d objects should be represented by a complex and detailed visible mesh and an invisible simplified shape used by a physics engine for collision detection (collider).

Detailed visible mesh.
Invisible physical representation by using simplified shapes.

Using simpler shapes#

Physical shapes compound of simple primitives make collision calculations easier while keeping performance high and accuracy acceptable. Therefore, it is recommended to rather approximate geometry with simple primitives (Sphere, Capsule, Cylinder, Box), which are faster and less memory demanding.

Complex shapes, such as Convex Hull and a set of autogenerated convex hulls, should be selected for representing complex and composite geometry when the other way is impossible.

A car can be approximated using one complex shape and several simple shapes.

At the same time you should keep the number of shapes as low as possible in order to avoid heavy calculations leading to the performance drop. Remember that a shape doesn't have to duplicate the mesh it approximates. Even though it is not precise, in the majority of cases it will provide acceptable results.

Rough approximation is accurate enough.

Using simpler geometry#

The simpler geometry is used for surface collisions detection, the more performance will be gained.

If a mesh representing a physical obstacle has several levels of detail (LODs), the least detailed one is the most preferable for collision and intersection detection. Enable the Collision and Intersection options for this lod and disable for the other ones.

Use the lowest level of detail for intersections and collisions.

Approximating collision shapes by using primitives is also a good practice. You can apply the following approach:

  1. Disable the Collider Object option for the original node. Since now it will not be taken into account by collision detection.

  2. Add a cylinder object to the scene by choosing Create -> Primitive -> Cylinder in the Menu Bar and cover the original mesh with the primitive.

  3. Make sure that the Collider Object flag and the Collision option of the surface are enabled for the primitive node.
  4. Hide the visual representation of the primitive's surface. You can do it either by clearing its Veiwport and Shadow masks or simply by setting its Max Visibility parameter to the negative infinity (-inf) - thus ensures that the surface will not be visible on any distance.

    So now the detailed mesh is providing only visual representation while physical interactions are calculated for the primitive cylinder.

Collision Detection Approach#

As far as Continous Collision Detection is a very demanding operation, use this approach only for fast-moving objects and objects requiring precise calculations.

In most cases Descrete Collision Detection should be used instead. For this purpose, select a shape and uncheck the Continuous flag for it.

Notice
Continuous collision detection is available for sphere and capsule shapes only. So, for other shape types it is not needed to pay attention to the collision detection approach.

Optimizing Physical Bodies#

Freezing#

Freezing is recommended to be always applied to all Rigid, Ragdoll and Fracture bodies. It allows saving a great deal of computational resources by skipping physical calculations of immobile objects until they are affected by any force or object.

To enable freezing, perform the following steps:

  1. Enable the Freezable flag for all types of physical bodies listed above.
  2. Set appropriate values of the Frozen Linear Velocity and Frozen Angular Velocity for each physical body or adjust the global parameters. These global freezing thresholds are compared to the ones set for each body, and the highest value is chosen to freeze the body.

  3. Adjust the number of Frozen Frames. The lower the value, the faster objects get frozen.

Fracturing#

Although the fracture body is a relatively inexpensive type, in case of large number of fracture pieces, the impact on performance may become significant. To avoid performance drops the following tips can be used:

  • Use the Volume Threshold parameter to reduce the number of fracture pieces.
  • Remove the pieces of a fractured body from the scene.
A code-based example, illustrating how to remove (fade with the time) the fracture pieces from the scene can be found in the Physics section of the UnigineScript samples.
Last update: 2018-12-27