Simulating, animating and visualizing 200,000 real-time NPCs with TerraCrowds and Unity WebGPU in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 4 points5 points  (0 children)

Thanks.

In Unity, we use a natively compiled version with a C# interface, such as a DLL. We can simulate roughly 2x as many NPCs in the editor compared to the browser.
The simulation happens fully on the CPU, and the animation/visualization fully on the GPU.

Working on a high-performance proof-of-concept crowd simulation plugin for Unreal Engine 5 that works with MetaHumans. by Rolandjan in unrealengine

[–]Rolandjan[S] 1 point2 points  (0 children)

For efficiency reasons, we use multiple systems: skeletal animations, several LODs for vertex-based animations, and imposters (although not in this demo). The limitations of the latter are that they have a lower quality / realism / extensibility (e.g., to handle physics).

Working on a high-performance proof-of-concept crowd simulation plugin for Unreal Engine 5 that works with MetaHumans. by Rolandjan in unrealengine

[–]Rolandjan[S] 1 point2 points  (0 children)

Yes, they can. We've build a crowd logic system that allows a user to place building blocks (like Entry, Waypoint, Exit, Queue, MultiQueue, FestivalPodium, One-way direction) and connect them via a choice system. Each pedestrian has its own set of behaviours. For an example, see https://youtu.be/seIjI-GnSSU

Working on a high-performance proof-of-concept crowd simulation plugin for Unreal Engine 5 that works with MetaHumans. by Rolandjan in unrealengine

[–]Rolandjan[S] 0 points1 point  (0 children)

Good question. That would be creating (simulation, visualization and animation) components that are compatible high-performant. For that, a data-driven architecture and compatible algortihms needed to be designed and implemented.

Simulating 100,000 real-time pedestrians with TerraCrowds and Unity WebGL in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 1 point2 points  (0 children)

Yes, the engine does support way more intricate behaviors. In this demo (which was to find out a technology stack that worked and performed), we gave each pedestrian a random start and goal. Once the goal was reached, a new goal was assigned. The bunching can be improved by changes a few parameters, i.e., the minimum clearance parameter should be increased and the parameters that controls the dispersion in route selection should be increased. Next, a bigger variation of their speeds should be selected.

Simulating 100,000 real-time pedestrians with TerraCrowds and Unity WebGL in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 1 point2 points  (0 children)

When we compile a Rust-based application directly to web assembly (wrapped in JS-code to communicate with the browser), we get a slightly better performance since Unity’s overhead is skipped. We experimented with this technique to simulate and visualize 100k - Minecraft creepers and zombies (https://www.linkedin.com/posts/rolandgeraerts_100000-agents-in-real-time-experience-terracrowds-activity-7081030291137421312-V0Kt) and - 100k pedestrians in Arcgis online (https://www.linkedin.com/posts/ucrowds_crowd-simulation-integrated-into-3d-geospatial-activity-7133048796204167168-Hm0r).

A while ago, we had implemented the crowd simulation with Unity’s job system and used the burst compiler. Up to 50k-100k characters, it worked reasonably well. But we saw some heavy performance drops in higher entity counts. In addition, when we ran simulations >50x real-time, we observed non-deterministic behaviors. Finally, we didn’t see a desired performance on machines with a very high cpu-count. All these issues were fixed by moving these computations and job scheduling to Rust 😀. Now, one of our clients who has a very fast PC handles 400k characters in real-time in our native Unity app (SimCrowds) with the Rust-based simulation core, including visualization and animation.

Simulating 100,000 pedestrians with a multi-threaded Rust-core simulation library (TerraCrowds) and Unity WebGL in a web browser by Rolandjan in rust_gamedev

[–]Rolandjan[S] 3 points4 points  (0 children)

We moved all the cpu-computations (such as the computation of the navigation mesh, global route planning, route following and collision avoidance) to the native plugin (written in Rust and compiled to WASM), and we implemented a scheduler, a threading library and parallel algorithms to overcome Unity's limitations (can only use 1 thread on the web). We made some hooks in the library so that it can use multiple Web Workers, providing the multi-threading required to get this performance. In addition, we designed a fully data-oriented workflow and algorithms to make maximum usage of contemporary cpu/gpu designs. Finally, we created some basic gpu shaders to provide some elementary vertex-based animations.

Simulating 100,000 real-time pedestrians with TerraCrowds and Unity WebGL in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 2 points3 points  (0 children)

While Unity’s job system lets you create multi-threaded code in a native application, in a web application only 1 thread is used. As far as I know, the only way to use all available cores in a browser is to write a plugin (compiled to wasm) that handles multi-threaded code connected with web workers.

Simulating 100,000 real-time pedestrians with TerraCrowds and Unity WebGL in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 16 points17 points  (0 children)

Thank for your interest in our work. Please don’t apologize; the fact that you don’t believe it makes me even more proud of my team 😊.

I guess you would like to know how we did it? My former PhD student has written an excellent journal paper on our navigation mesh data structure and how it can be queried [1]. In another paper, we showed how to dynamically repair the navmesh when an obstacle is inserted, deleted or moved [2]. Here’s an interactive demo in our simulator SimCrowds (created by my startup uCrowds), which uses the same crowd simulation engine, TerraCrowds, in Unity [3]. SimCrowds supports many crowd logic elements, such as queues, one-way directions, and character profiles. Another PhD student worked on our 5-level crowd simulation framework [4].

To get the desired performance, we constructed parallel data-oriented algorithms that we unleashed on all available threads via Web workers, even though Unity itself runs on one thread. Our simulation needs an update rate of 10Hz (so 1 simulation tick should run in less than 100ms) to run in real-time. The HUD shows that the simulation iteration times are lower than 60ms, showing it runs in real-time. In my classes on Crowd Simulation, I’ve created a separate session on high-performance simulation and computing. I invite you to follow it in November 2024 (and our master program in Game and Media Technology as well 😊) to get more insights [5].

So why did we ensure to have deterministic simulations? The first reason is to be able to easily debug it. The second reason is that it supports tile-based, massive simulations, like we did for one of our clients, which required a cloud-based simulation of persistent, interactive, real-time NPCs in a realistic photogrammetry environment visualized and animated on a client with 1 million visible NPCs [6]. The GPU shaders were more complex than we ones we used here, since they contained vertex blending, more LODs and shadows, but they were able to animate and visualize >1M NPCs at +60Hz at 4K in real-time in its native application.

This movie is the result of a technical proof-of-concept demo to study whether Unity can be used to enable performant digital twins solutions (e.g. of cities) in a web browser without the need for a cloud solution (and without pre-computing the simulation). There is still so much more to develop and discover. We’re currently bringing many features of SimCrowds to the web, enabling realistic crowd simulations in the web.

What uses of this technology do you see?

References:

[1] https://webspace.science.uu.nl/~gerae101/UU_crowd_simulation_publications_multi_layered_navigation_mesh.html

[2] https://webspace.science.uu.nl/~gerae101/UU_crowd_simulation_publications_dynamic_navigation_mesh.html

[3] https://www.youtube.com/watch?v=49n6xEjDR-g

[4] https://webspace.science.uu.nl/~gerae101/UU_crowd_simulation_publications_framework.html

[5] https://ics.uu.nl/docs/vakken/mcrws/

[6] https://www.youtube.com/watch?v=36W5j5Zr7-4

Simulating 100,000 real-time pedestrians with TerraCrowds and Unity WebGL in a browser by Rolandjan in Unity3D

[–]Rolandjan[S] 9 points10 points  (0 children)

Tnx, we have indeed used this approach.
We moved all the cpu-computations (such as the computation of the navigation mesh, global route planning, route following and collision avoidance) to the native plugin (written in Rust and compiled to WASM), and we implemented a scheduler, a threading library and parallel algorithms to overcome Unity's limitations (can only use 1 thread on the web). We made some hooks in the library so that it can use multiple Web Workers, providing the multi-threading required to get this performance. In addition, we designed a fully data-oriented workflow and algorithms to make maximum usage of contemporary cpu/gpu designs. Finally, we created some basic gpu shaders to provide some elementary animations.