[Unity] Thousands of people share the same screen, from getting started to giving up - multi-threaded RVO obstacle avoidance

16688842:

Can massive objects be placed on the same screen without using Dots? Many games with grand scenes, especially rougelike games, often have thousands of monsters filling the screen, and the thrill of mowing the grass to clear the screen is heartfelt, so these types of games are very popular, but how do you do it?

First of all, it is not feasible to use pathfinding for massive moving objects. Even A* Pathfinding Pro that supports multi-threading will start to drop frames seriously after only three to five hundred.

test environment:

Unity 2022.3.9f1, URP 14.0.8

The number of model vertices is 1195, the number of LOD1 vertices is 858, and the number of LOD2 fixed points is 530.

PC:i7-13700KF + 3070 8G;

Mobile Android: Snapdragon 8 gen2;

RVO obstacle avoidance test on PC:

 When testing the Unity Editor on the PC, the game almost dropped to 50 frames with only 5,000 people. The late emperor collapsed before he started his business. CPU-side performance consumption is mainly due to RVO obstacle avoidance and KDTree calculation for each frame. However, using multi-threading is not a big problem. The biggest bottleneck is the GPU;

PC, 5000 people:

 On the mobile phone, the Snapdragon 8 gen2 real machine can no longer handle 3,000 people and drops to 24 frames. The HybridCLR hot update is used to interpret and execute, but even AOT can only improve it by about 5-10 frames.

Cell phone, 3000 people:

There is no doubt that Animator cannot be used for the animation part. It writes the vertex information of each frame of the skeletal animation to the Texture, and uses Mesh Render + Shader to read the position from the vertex Texture during runtime. SRP will automatically batch it:

Use LOD:

Okay, the pressure is on the GPU, so let’s lower the vertices to cool down the GPU. Using the LOD function, when LOD1 vertices are reduced by 30% and LOD2 by 60%, the effect is indeed significant:

With 5,000 people on the PC side, the number of frames almost doubles to about 100 frames:

 There are 3,000 people on the mobile phone, which is almost doubled, and the frame rate reaches 44:

 That's it? ? ? And this is the performance without complex game logic, which will be greatly reduced in actual projects. It seems that using the traditional method is not only difficult for thousands of people to share the screen, but also for thousands of people.

Conclusion: The limit of traditional methods is the level of thousands of people sharing the screen, so give up!

However, RVO is still needed for obstacle avoidance. The test project is modified based on the open source RVO2 C# version: GitHub - snape/RVO2-CS: Optimal Reciprocal Collision Avoidance (C#)

 The following main changes have been made to the original RVO:

1. Use Easy Threading to refresh RVO Agent in parallel;

2. Add the function of deleting Agent;

3. Increase the Agent obstacle avoidance weight setting. For example, after setting the weight of the Agent that reaches the target location to 0, it will not be crowded out by other Agents;

4. Add shape obstacles, BoxObstacle, CircleObstacle, EdgeObstacle;

5. Performance optimization, use ArrayPool instead of creating arrays every frame;

6. RVO.Vector2 is changed to Unity Vector2, and RVO.Math is optimized to avoid exceptions caused by the denominator of the original version being 0.

RVO2 Unity modified version: GitHub - sunsvip/UnityRVO2: RVO for unity

Guess you like

Origin blog.csdn.net/final5788/article/details/132891595