This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

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 are not calculated. If the distance between the camera and the physics-based node exceeds this limit, the node freezes and its physical calculations are 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.
  • Using the Iterations parameter may increase stability, but can also result in a higher load. A 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 other objects. Most probably, objects can be divided into groups dedicated to certain tasks.

If you have multiple objects that take part in physical simulation, divide the ones that are hardly going to interact with each other, into different "groups" by using the Bit Masking mechanism.

Notice
The Surfaces tab of the Content Profiler tool allows filtering out surfaces that use a specific mask to facilitate the scene optimization.

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

In Unigine, you can set up filtering accurately by using the Exclusion Mask. This mask allows ignoring shapes with the matching exclusion masks regardless of their Collision Masks.

Surfaces that 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.

Avoiding detection of undesired and unnecessary collisions is a basic way to reduce the amount of physical calculations.

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

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 consisting of simple primitives make collision calculations easier while keeping performance high and accuracy acceptable. Therefore, it is recommended to 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 simple shapes don't allow achieving the desired goals.

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 primitives are not precise, in most cases they 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 them 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. Ensure that the original node is not a Collider — check that Collision flag is disabled for its surfaces, bodies, and shapes. Since now it is not 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 Collision option of the surface is enabled for the primitive node.
  4. Hide the visual representation of the primitive's surface. You can do it either by clearing its Viewport and Shadow masks or simply by setting its Max Visibility parameter to the negative infinity (-inf) — this ensures that the surface is not visible at any distance.

    Now the detailed mesh provides only visual representation, while physical interactions are calculated for the primitive cylinder.

Collision Detection Approach#

Continuous Collision Detection is a very demanding operation, therefore, it is recommended to use this approach only for fast-moving objects and objects requiring precise calculations.

In most cases, Discrete Collision Detection would be enough. 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.

Optimizing Physical Bodies#

Freezing#

It is recommended to enable Freezing to all Rigid, Ragdoll, and Fracturebodies. This 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 parameters 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: 2023-06-22
Build: ()