Accurate Real-Time Physics Simulation for Large Worlds
Total Page:16
File Type:pdf, Size:1020Kb
Accurate Real-time Physics Simulation for Large Worlds Lorenzo Schwertner Kaufmann, Flavio Paulus Franzin, Roberto Menegais and Cesar Tadeu Pozzer Universidade Federal de Santa Maria, Santa Maria, Brazil Keywords: Real-time Physics Simulation, Physics Engines, Large-scale Simulations, Floating-point Imprecision. Abstract: Physics simulation provides a means to simulate and animate entities in graphics applications. For large envi- ronments, physics simulation poses significant challenges due to the inherent known limitations and problems of real number arithmetic operations. Most real-time physics engines use single-precision floating-point for performance reasons, limiting simulation with a lack of precision that causes collision artifacts and positioning errors on large-scale scenarios. Double-precision floating-point physics engines can be used as an alternative, but few exist, and fewer are supported in game engines. In this paper, we propose an efficient solution capable of delivering precise real-time physics simulation in large-scale worlds, regardless of the underlying numeric representation. It implements a layer between high-level applications and physics engines. This layer subdi- vides the world into dynamically allocated sectors which are simulated independently. Objects are grouped into sectors based on their positions. Redundant copies are created for objects crossing sectors’ boundaries, providing seamless simulation across sector edges. We compare the proposed technique performance and precision with standard simulations, demonstrating that our approach can achieve precision for arbitrary scale worlds while maintaining the computational costs compatible with real-time applications. 1 INTRODUCTION pressing infinite real numbers into a limited amount of bytes requires an approximate representation (Gold- Physics simulation plays a fundamental part in many berg, 1991). IEEE-754 floating-point represents real virtual scenarios across a broad range of applications, numbers as d × be, where d is a significand, b is including games, films, and simulations. Physics are a base, and e is an exponent, thus rounding error simulated using physics engines —low-level middle- increases proportionally to value magnitude. Most ware that provides support to physical behaviors, such arithmetic operations using values represented with as fluids, soft and rigid bodies simulation. Games and floating-point precision produce results that cannot be simulations rely on real-time physics engines to pro- represented using a fixed amount of bits, thus requir- vide dynamic, immersive scenarios. For performance ing rounding. reasons, most of these engines operate with single In physics simulations, the rounding error in- floating-point precision, enough to cover a wide range creases proportionally to objects’ distance from the of applications. However, for large-scale scenarios, origin on which the simulation is continuously per- these engines present a limitation due to the low ac- formed, and error accumulates over error. Empiri- curacy of the floating-point numbers, especially when cal experiments suggest that single-precision floating- representing big numbers. Simulations for objects far point limit is 104 units (Unity Community, 2018); from origin might use imprecise values, causing fail- while others define it at 5×103 units (Unity Commu- ure in the collision detection algorithms, varying from nity, 2017), or within the range of 4 × 103 to 8 × 103 small intersections that do not compromise the over- units (Burk et al., 2016). Thus, applications with sce- all simulation to big intersections that spoil the simu- narios larger than these dimensions are susceptible lation (e.g., vehicles falling off a terrain). Moreover, to numerical inaccuracy and may present problems nowadays, it is noticeable that 3D games and graph- throughout the physics simulation. ical simulations, used for training or amusement, are In terms of accuracy, some physics engines are dealing with constantly expanding scenarios, thus re- designed to support double (e.g., Bullet and New- quiring solutions to enable proper visualization and ton Dynamics) instead of single-precision to repre- simulation of moving entities. sent the physics components and provide more accu- Floating-point imprecision occurs because com- racy in calculations. Double-precision math (and thus 135 Kaufmann, L., Franzin, F., Menegais, R. and Pozzer, C. Accurate Real-time Physics Simulation for Large Worlds. DOI: 10.5220/0010194501350142 In Proceedings of the 16th International Joint Conference on Computer Vision, Imaging and Computer Graphics Theory and Applications (VISIGRAPP 2021) - Volume 1: GRAPP, pages 135-142 ISBN: 978-989-758-488-6 Copyright c 2021 by SCITEPRESS – Science and Technology Publications, Lda. All rights reserved GRAPP 2021 - 16th International Conference on Computer Graphics Theory and Applications double-precision matrix and vector APIs) cannot take quired information for its correct simulation —this as much advantage of SIMD instruction sets (Ericson, requirement is termed awareness. Different tech- 2005), which are generally sized to support and vec- niques focus on partitioning their agents into groups tors that have 32-bit wide components. Few physics while keeping a low number of overlapping between engines support double floating-point precision and regions of interest of objects in different partitions game engines, such as Unity, Unreal Engine 4, Cry —this problem is termed communication level. Be- Engine 3 and Godot do not natively support them. sides it, the distribution of simulations introduces An alternative to increase numerical precision is other problems, such as well-balancing the simulation the origin shifting approach. This approach estab- load across the available processing nodes and how lishes a real-time center point (e.g., the observer po- to operate efficiently since the partitioning algorithms sition), and 1) physics simulation considers the cen- themselves might not scale well. ter point as the Cartesian origin or 2) the objects are (Lozano et al., 2007) explores a complete frame- shifted to the Cartesian origin, having a center point work for scalable large-scale crowd simulations. as a reference, maintaining the same layouts of ob- Their solution successfully provides scalability while jects’ position. In an efficient and precise way, this providing awareness and time-space consistency. approach guarantees the physical simulation for any This is achieved using rectangular grids and dividing dimension of the scenario. However, physics objects the agents according to their position in the grid. must be close to an arbitrary center point. Otherwise, (Vigueras et al., 2010) improves efficiency of pre- inaccuracy errors remain. For sparsely distributed vious methods by employing the use of irregular simulations, e.g., multiplayer games, origin shifting shapes regions (convex hulls). Their results show that does not work. irregular shapes outperform techniques with regular We present a solution compatible with real-time ones, regardless of the crowd simulation. simulations that expands state-of-the-art physics en- (Wang et al., 2009) proposes a technique for parti- gines, ensuring physics simulations enough precision, tioning crowds into clusters, minimizing communica- regardless of the world scale and underlying numeric tion overhead. Their work achieves great scalability representation. Our solution is implemented as a layer through the application of an adapted K-means clus- between high-level applications and physics engines. tering to efficiently partition agent-based crowd sim- This layer split the world in sectors and adds re- ulations. dundancy to each sector, ensuring each part has all Newer techniques explore further performance the required information to, independently, be sim- improvement, either minimizing communication ulated without inconsistencies close to the Cartesian costs, equalizing balancing, or both, while efficiently origin. Furthermore, our solution benefits from how doing so. For example, (Petkova et al., 2016) large-scale worlds application must implement world uses community structures to group related agents streaming due to memory and processing limitations, among processors, reducing communication over- amortizing space partitioning cost. The main con- head. (Wang et al., 2018) explores parallelizing tribution of our work is a novel solution that pro- the simulation per agent using the Power Law in vides arbitrariness in sparse simulations precision, CUDA architecture to ensure behavior synchroniza- enabling floating-point engines to increase precision tion across threads. Their solution explores minute and/or scale. model details while improving efficiency. This paper is organized as follows: Section 2 pro- (Brown et al., 2019) propose a solution applying a vides background and related works on the subject. partitioning solution for physics servers with horizon- Section 3 discusses all the steps of the proposed so- tal scalability. In their work, the scenario is parti- lution in-depth. Section 4 discusses the effects of tioned in regions using Distributed Virtual Environ- the sector size choice. Results are evaluated and dis- ments modeling, and each partition is assigned to cussed in Section 5. Finally, Section 6 presents con- a server for physics simulation. Objects interacting clusion and directions for future work. across partition boundaries are handled by projecting objects in overlapping regions to guarantee a seamless simulation.