EnViron
EnViron is a VR game developed in 3 weeks in a team of 4 for CS23 at Dartmouth College final project. It was a fortune to work with talented teammates Chase(Dev), Ana(Dev) and Nellie(Design). The Github Repo is here!
Game Premise
You are a virus and your mission is to infect your host by navigating through a procedurally generated vascular system, infecting organs like the heart, lungs, and kidneys, with the ultimate goal of finding and crossing the blood brain barrier to fully infect your host.
In this VR game, the player commands a virus from a control room inside the virus. To navigate, the player uses an interactable “control virus” whose movements are reflected by the virus vessel they are in. They have to explore the map, infecting different organs, searching for the blood brain barrier. An organ, once infected, serves as a respawn point for the player. There is a chance that the infected organs are purged by the body and a respawn point is deactivated. Killer T Cells (white blood cells) wander the map and try to kill the player, who if killed without an active respawn point the game is over.
Video
Technical Details Behind the Game
The working process was split into 3 main parts: algorithm for generating naturalistic vascular systems, instantiating cells along the generated vascular systems, locomotion control over VR, and artistic design to make it a compelling experience. For the project, I mainly worked on the instantiating and artistic control parts.
Given the amazingly realistic and complex system generated by Chase, who made a detailed and separate Github Repo here where you can grab and use, I worked on how to convert the system to smooth the polylines to curves and instantiating different types of cells along the vascular system.
I eventually chose Catmull-Rom spline. There are several considerations of this kind of curve. First, it smooths out the whole environment, avoiding sharp corners which are not natural in the human body. Second, we want to find a parameterization method for a curve that must pass through the control points. This is necessary for accurate control over the path. Finally, we want to provide a method for navigating our enemies (T-cells who try to catch and eliminate the player). We want to circumvent the AI navigation and resort to a simpler way. The parameterized curves, especially for Catmull-Rom Spline, perfectly fit our need, which we can control the movement of the enemies using a single parameter t. The enemies are in 3D, flying around the space, and the AI navigation is mainly designed for 2D. That's why we want to avoid using AI navigation.
Catmull-Rom Spline Implementation
The Catmull-Rom Spline is mathematically a function mapping R to R^3. Given a parameter t from (0, 1), it automatically maps t to a 3D position on the curve (also returns the gradient/tangent).
The spline is quite simple. You can find a detailed explanation on Wikipedia. There's one nice property which I personally think is the most distinctive about the spline: the tangent of the curve at a point (say p_2 in the figure) is always given by the vector from p_1 to p_3. Along with the property that the curve passes through all control points, one can arrive at the expression for the curve. More specifically for our project, we added a "radius" parameter to each control point, achieving the goal of controlling the vessel radius smoothly by interpolation.
A Unity editing tool for procedural generation
I created a Unity Editor tool for artistic control and design using random processes (mainly gaussian) integrating Chase's tree data structure by a modified version of preorder traversal (since we might traverse the bifurcation nodes multiple times to construct different curves). In the tool, by controlling:
- the weights and the prefab of the cell;
- the variation and the min value of the path's radius;
- the variation and min value of the cell size;
- the cell density;
- the random seed;
- the noise texture's size (an N*N texture generated in advance).
the designer can control one region's appearance. Concisely, the cells are drawn on random frames with radius R frame along the curve. The vessel radius R and the cell size are controlled by 2 different normal distributions.
KD-Tree Optimization
Before optimization, we have 107490 cells, 304749 Batches, 252.8M triangles and 246.5M vertices in the scene. This makes no sense to render in VR. Even on a Windows PC with a 5080 RTX, the framerate was only 35 FPS. To optimize the rendering, I chose KD-Tree - only selecting cells within a sphere of radius R around the player to render. Since the scene is static, I only need to build the tree once at the start of the game. And since we want to query objects within a range in space, KD-Tree, a spatially partitioning data structure, is a perfect fit.
After optimization, we have about 947 Batches, 8.5M triangles and 7.1M vertices in the scene during runtime. This improved the FPS from 35 to ~300 FPS on a Windows PC with a 5080 RTX. Most of the code is adapted from the implementation by Viliwonka[1].
However, even with KD-Tree optimization: Since there are too many cells in the scene, each query will still be costly. To further improve the performance, I reduced the frequency of querying - instead of querying every frame, I queried only when the player has moved a certain distance from the last query position - a virus does not move very fast!
Visual Control
For the game, I modeled the cells for the environment, including 9 cells for 5 different type of regions. They are all modeled and procedurally textured in Blender.
And after adding environment map, fog, local volumes and tweaking with the post process, this is how everything looks like during the exhibition for Dartmouth technigala. There's still a lot to do, but we believe we've made our best during the intense time window.
Acknowledgement
Again, it was great fun and my fortune to work with great teammates. Chase - who did a great job on the complex PCG algorithms. Ana - who made amazing and creative locomotion in VR and enemy AI. Nellie - a great artist who made various models and designs to add style to the game. Lastly, thanks to Prof. Mahoney and all the great TAs. CS 23 is a great course for everyone who wants to do Unity and/or AR/VR development!