Reader small image

You're reading from  Enhancing Virtual Reality Experiences with Unity 2022

Product typeBook
Published inNov 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804619537
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Steven Antonio Christian
Steven Antonio Christian
author image
Steven Antonio Christian

Steven Christian is an Augmented Reality Developer, Animator, and Medical Student Student. He's also the Owner of Iltopia Studios where he creates comics and cartoons that explore the Black experience in America. He is Unity Certified 3D Artist and Instructor and his goal is to improve equity in arts and technology through content creation and community-focused education.
Read more about Steven Antonio Christian

Right arrow

Optimizing Your Virtual Reality Experiences

In this chapter, we will cover a variety of ways to improve our VR experience during and after development, including tried-and-true optimization techniques that enhance usability and accessibility. Unity offers best practices and tools for optimization, and there is a wealth of information available online and in asset stores to improve your VR experiences.

In an ideal world, we wouldn’t need to optimize because everything we create would run flawlessly on every device. However, this is not the case.

By the end of this chapter, you will understand the importance of optimization in making or breaking the experiences you hope to create. As a developer, you are aware of the effort and challenges that optimization requires, but this chapter will equip you with skills and approaches to improve the performance of your VR experiences, regardless of the intended device.

In Phase 10 of our roadmap, we introduced optimizations, such...

Optimization in Unity

Optimization is a critical aspect of developing interactive experiences such as games, animated videos, and VR applications. It focuses on improving performance and ensuring accessibility and playability, while minimizing issues such as lags, bugs, and other problems that could lead to user discomfort, such as nausea or vertigo.

Early optimization during development is essential as it allows for seamless performance across various devices without sacrificing visual quality. This practice also prevents potential challenges that may arise when trying to optimize a project after it has been fully developed.

Profiling plays a crucial role in the optimization process, as it helps developers identify specific areas that require improvement based on their individual projects. Since each project is unique, developers need to examine their Profilers to pinpoint performance bottlenecks and prioritize optimization efforts accordingly.

Achieving a high frame rate...

Optimizing draw calls

One critical aspect of optimizing VR applications is reducing draw calls, which are commands sent to the GPU to render a mesh. The number of draw calls can quickly add up and have a significant impact on performance.

To optimize draw calls in your VR experience, follow these steps:

  1. Combine meshes using Blender or Maya to reduce the amount of faces to render for each asset:
    1. In Blender, select all objects you want to combine and press Ctrl + J. The last object selected will be the new origin.
    2. In Maya, select all objects and go to Mesh | Combine.
    3. Save the combined mesh as a separate file for easy editing later on.

Note

This step is only helpful for performance when the combined meshes share the same material.

  1. Share materials among different GOs to achieve good batching. This reduces the number of unique instances and allows for more efficient use of resources.
  2. Use a single material with a texture for coloring different parts of an object...

Optimizing material settings

Optimizing materials is essential for enhancing the performance and user experience of Unity games and VR applications. By streamlining material complexity, enabling GPU instancing, and using appropriate shaders, developers can significantly increase rendering speed, reduce memory usage, and achieve a stable 90 fps on target devices similar to Oculus Quest 2. This optimization ensures a visually appealing and responsive VR experience for users.

GPU instancing

By utilizing various techniques such as batching, GPU instancing, and choosing appropriate settings, we can ensure that our VR content runs smoothly at 90 fps while maintaining excellent visuals on the target device. To achieve this, we will delve into specific optimization tips and step-by-step instructions to maximize the performance and efficiency of your VR project.

To improve performance when rendering multiple instances of the same object with the same mesh and material, consider using...

Optimizing camera settings

Understanding Unity camera settings is essential for boosting your VR experience’s performance. The camera renders everything in the scene, and knowing which options to adjust can lead to significant performance improvements. Two important settings are the camera clipping planes and camera field of view (FOV), which determine how much the Unity camera can view. However, be cautious not to set these values too low, as it may prevent the camera from rendering essential elements.

In the next section, we will optimize our camera settings by adjusting the FOV.

FOV

Adjusting the camera’s FOV can significantly impact the overall performance, as it determines the number of objects being rendered on the screen at once. In this section, we will discuss how to optimize the FOV for an optimal VR experience while maintaining good visuals and performance on the target device.

To optimize the FOV for a VR experience, follow these steps:

    ...

Optimizing images and textures

Texture optimization involves configuring texture map settings such as resolution, format, compression, and mipmapping to balance performance and image quality. In this section, we will discuss best practices and step-by-step instructions for optimizing textures in Unity to achieve the desired results.

To optimize textures in Unity for VR experiences, follow these steps:

  1. Select the texture in the Unity project.
  2. In the Inspector window, enable the Generate MipMaps option.
  3. Set Max Size to an appropriate value, such as 512. For UI elements, you can use 128 or 256.
  4. Enable the Crunch Compression option.
  5. Set the Quality value to balance between compression and image quality, such as 50.
  6. Click Apply to save the changes.

We can repeat these steps to apply to all of our textures and images in our VR scenes so that we save space and improve our rendering speed. In the next section, we will explore optimizations for our audio...

Optimizing audio files

Efficient audio management helps maintain high frame rates, reduces memory usage, and minimizes latency, ensuring a smooth and enjoyable experience for the user. In this section, we will explore various tools and best practices for optimizing audio in Unity, targeting an optimal performance of 90 fps and high-quality visuals on standalone VR devices.

To optimize audio in Unity for VR experiences, follow these steps:

  1. Select the audio file in the Unity project.
  2. Enable the Force to Mono option for 3D audio sources to save memory, as 3D audio essentially plays in mono. This does not affect the sound quality but reduces the file size.
  3. Enable the Normalize option to adjust the gain of the mono sound to the same volume as the original audio file.
  4. Set these options based on your requirements to manage how and when audio files are loaded in your VR application.
  5. Enable the Ambisonic option if the audio file has ambisonic encoded audio.
  6. Choose...

Optimizing animation files

Animations play a vital role in creating immersive and engaging experiences in games and VR applications. However, they can also significantly impact performance if not optimized effectively. By utilizing proper optimization techniques, developers can enhance the performance of animations in Unity, ensuring smooth and responsive gameplay or VR experiences for users.

High-frame-rate animations can consume substantial resources, leading to decreased performance. It’s essential to evaluate the current frame rate of your animations to identify potential areas for optimization. To improve performance, consider lowering the frame rate of animations in the Timeline. This will reduce resource consumption and lead to a more responsive experience. For optimal performance on the target device, aim for animations to run at 90 fps.

The best way to optimize our animation files is to reduce the keyframes. We will explore that in the next section.

Keyframe...

Optimizing the lighting system

VR experiences require optimization tools and best practices to achieve the best possible performance and visual fidelity. One crucial aspect of optimizing VR experiences is managing lighting, as it can greatly impact both visual quality and performance. By following these guidelines, developers can create VR experiences that run smoothly at 90 fps on target devices.

The best way to optimize our lighting system is to explore light baking, which we will do in the next section.

Light baking

Creating immersive and high-quality VR experiences requires a balance between visual quality and performance. To achieve optimal performance on target devices, it is essential to utilize optimization tools and best practices. One critical aspect of optimizing VR experiences is the efficient management of lighting within the scene, which can be achieved through a process known as baking. In this section, we will discuss the benefits of baking lights, how to perform...

Optimizing project settings

Optimizing project settings in Unity is an important step to ensure that your project runs smoothly and efficiently. The settings that you can optimize include Rendering, Physics, Audio, and Scripting. For example, in the rendering settings, you can adjust the graphics quality and set up LOD to improve performance. In the physics settings, you can adjust the timestep and gravity to ensure that the physics simulation runs smoothly. In the audio settings, you can optimize the audio quality and set up audio occlusion to ensure that sounds are only heard in the appropriate areas. In the scripting settings, you can adjust the compilation settings and choose the appropriate scripting backend to optimize the performance of your code. By optimizing these settings, you can improve the performance of your Unity project and ensure that it runs smoothly on different devices and platforms.

We will go through some settings that all VR experiences must have so that...

Applying optimizations to our VR world

Throughout the first half of this book, we laid a strong foundation. In the second half, we dove deep into design thinking and the entire development process, bringing to life a dynamic virtual world. This world boasts a powerful VR rig, an expansive environment, and even an animated show that plays at its center. However, if you’ve tested it by pressing play, you might have noticed it doesn’t perform as smoothly as desired.

In this section, we’ll delve into optimizing our VR scene. Using the insights gathered in this chapter, our goal is to free up memory bandwidth and enhance frame rates during real-time playback. To achieve this, we need to first understand how our scene functions. Unity’s profiling tools will be invaluable in this endeavor, allowing us to pinpoint what affects the runtime experience.

Assessing our scene

Let’s begin by entering play mode to evaluate our VR scene’s performance...

Summary

In the final stretch of our VR journey, we’ve dug deep into the art of optimization. We’ve used all the Unity tools at our disposal, including compression and the Unity Profiler, to keep a keen eye on our frame rate and performance throughout the runtime.

We’ve fine-tuned our camera settings, squished our images to lighten their load, and even given the same treatment to our audio files. After all, while we love a rich soundscape, we can’t afford to let it weigh us down.

We’ve even done some spring cleaning on our 3D models, trimming the fat on mesh and draw calls, and cutting out the excess frames on our animation files. We’re even baking our lights so we can keep things bright without slowing things down.

We’ve also revisited our project settings to tweak the quality of our rendering and the backend player settings. It’s all about making our algorithms work for us, not against us. This keeps things running smoothly...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Enhancing Virtual Reality Experiences with Unity 2022
Published in: Nov 2023Publisher: PacktISBN-13: 9781804619537
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Steven Antonio Christian

Steven Christian is an Augmented Reality Developer, Animator, and Medical Student Student. He's also the Owner of Iltopia Studios where he creates comics and cartoons that explore the Black experience in America. He is Unity Certified 3D Artist and Instructor and his goal is to improve equity in arts and technology through content creation and community-focused education.
Read more about Steven Antonio Christian