Technology Stream: 12 Unity5 Tips for Optimizing VR Apps!

â–¼ Technology Stream: 12 Unity5 Tips for Optimizing VR Apps! From Baidu VR VR applications require more computation than non-VR applications. Performance optimization is a very important task. If the target platform is a mobile device like GearVR, optimization is even more important. Here are some performance metrics that you should try to understand: 50 draw calls per eye. Unity5 more accurately calls it SetPass Calls. The number of vertices in the scene is less than 50K to 100K and the number of faces is less than 50 to 100K. Here are some simple tips for meeting the above requirements: Static batch processing There may be a lot of static geometry in the scene, such as walls, chairs, lights, and grids that never move. Mark them as static objects in the editor. To bake lightmaps, make sure to mark them static. Instead of letting each object lead to a draw call, the objects are marked as static objects that can be combined into a grid. Static batching has a key requirement: All objects must use the same material. If the static wall is made of wood and the static chair is made of iron, all the walls will be batched into one draw call and the chair will be used as a separate grid for additional draw calls. Texture set As mentioned earlier, each texture will cause a draw call. Intuition may be that wooden doors and iron chairs require different materials because of their different textures. However, if you use the same shader, you can use texture sets to create a common material for them. The texture set is a large texture containing all the small textures. Instead of loading multiple times with multiple materials, we can use one material to load one texture. Each object can correspond to a texture in different coordinates in the texture set. You can manually generate texture sets in the drawing pipeline, but Juan Sebastian's Pro Draw Call Optimizer tool is very useful. It can generate texture sets and does not confuse resources when replacing new objects. Dynamic batch processing Non-static objects can be dynamically batched as a single draw call. I have noticed that this process takes up a lot of CPU and is calculating every frame, but this is a good optimization. This is valid only for objects that use the same material and have fewer than 900 vertices. Using texture sets to create a material for all dynamic objects, you can perform simple dynamic batch processing. LODs (Multiple Levels of Detail) The LOD group is an easy way to improve performance. Use resources with multiple LODs and render objects away from the camera with low resolution geometry. Unity can automatically switch between LODs as the camera approaches. Fill rate, over drawing and cropping This is a topic worthy of attention. Reduce over drawing, the farthest object is drawn first, followed by the more recent objects in the top. This is no problem on a PC monitor with an average resolution of 1080P, but the problem is more serious for extremely high resolution VR and mobile devices. A large number of overdrawings make up a large number of pixels that affect the fill rate. Texture fill rate is the key to limiting GPU performance. Some solutions provide occlusion culling and frustum culling. Frustum culling means that objects outside the camera's view cone are not rendered. Don't render invisible objects! Occlusion culling removes objects that are blocked by other objects. For example, the room behind the door can be removed entirely. By default, occlusion culling is for the entire scene, and if the level is properly designed it can even eliminate the entire level in the game. The LOD group can of course also crop objects that are far away from the scene, further minimizing the fill rate. Level design If the game involves a player moving from one room to another, the simple solution is to have a level containing the entire game. The disadvantage is the memory consumption. Although each object and material in each room is not visible, it is still loaded into memory. Place each room in a separate level and intelligently load the level asynchronously in the code to improve performance. Asynchronous loading Load the next level before the player is about to enter the next room. Do not use Application.LoadLevel() to load synchronously, as it will cause the game to hang when loaded. Since the tracking of the helmet is real-time, this can lead to vertigo, which is too bad for the player. Use Application.LoadLevelAsync() to load the level. You can find how to use it in StartupSample.cs of the Oculus Mobile SDK BlockSplosion example. Light baking Turn off real-time shadows! Objects that receive dynamic shadows are not batched, which can result in severe draw calls. On a PC, you can achieve a very good dynamic shadow effect with a single real-time directional light. Realistic pixel-by-pixel shading is available for most modern PCs. On the mobile platform, however, you need to bake the light instead of the real-time shadows, baking the light with high resolution combined with soft and hard shadows to achieve a similar effect. shadow Especially for high-performance mobile experience, traditional techniques are used for shadow processing of 3D objects. You can simulate semi-real shadows by placing a simple 2D quad with a fuzzy shadow texture under the object. VR Tip: Do not try to use shadow buffering. Preprocess the lighting environment and use the old set of fuzzy shadow textures below the character. Light detector When using bake light, static objects work well but dynamic objects are a bit off. Light probes can be used to simulate simple dynamic lighting for dynamic objects. Light probes are baked cube maps that store direct, indirect, or even self-illuminating information from multiple points in the scene. When the dynamic object moves, it interpolates near the light detector to obtain light that approximates a certain point. This is a simple way to simulate real-time lighting on a dynamic object instead of costly real-time lighting. Unity's documentation explains how to place the light probe. Avoid using transparent and multi-material objects Glass-like objects that use transparent shaders consume performance. Making the wall look more realistic is a common practice, using a transparent material with a dusty or rusty texture, plus another separate base diffuser material. Multi-material alpha blending is very performance consuming. Each texture is incremented by one draw call! However, please note that multiple textures are not a problem, and using multiple materials is a performance-consuming task. Instead of using multiple individual materials, use a material-in conjunction shader to implement multi-text alpha blending. Skinned Grid Renderer Skinned grid renderers are often used on characters. They have animated joints that can use physical (doll) variations or custom animations (walk, jump, etc.) to achieve realistic mesh deformations. The bad news is: The skinned grid renderer does not support batch processing. For each eye, multiple draw calls are made for each character in the scene. There is no solution yet.

Posted on