A Reddit user Creo shared their method to optimize performance.
While this concept isn't exactly new, the game's style and the way the approach is presented certainly look charming. A Reddit user known as Creo shared a demo of their custom Unity renderer that uses GPU instancing to draw tree meshes. As a player approaches, it smoothly swaps the tree mesh for a GameObject with interactive components, allowing for actions like destruction, as shown in the prototype.
As the developer explained, the core idea is that all terrain tree transform matrices are drawn using Graphics.DrawMeshInstanced, excluding the indices of nearby trees. This list is populated with trees within a specific range of the player, using a quadtree for efficient calculations. Additionally, there's a pool of pre-instantiated tree prefabs, which are moved to the designated locations using those transform matrices. The result is that only a small number of actual GameObject trees exist, while the rest are rendered with DrawMeshInstanced for better performance.
As for limitations, Creo is implementing occlusion and maximum range culling to further optimize performance, but with around 20-40 million vertices on screen, depending on the camera angle, there's still room for more. The terrain features a total of 10,000 trees, and the renderer is getting about 30 FPS more compared to Unity's built-in method of rendering terrain trees with 3 LODs and imposters. However, the distance and quality of shadows still consume a significant portion of the FPS.
For more details, check out the original post here and see the developer's other creation for this project, a tool that stitches terrain and cave meshes together:
Join our 80 Level Talent platform and our new Discord server, follow us on Instagram, Twitter, LinkedIn, Telegram, TikTok, and Threads, where we share breakdowns, the latest news, awesome artworks, and more.