Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity 2020 Virtual Reality Projects - Third Edition

You're reading from  Unity 2020 Virtual Reality Projects - Third Edition

Product type Book
Published in Jul 2020
Publisher Packt
ISBN-13 9781839217333
Pages 592 pages
Edition 3rd Edition
Languages
Author (1):
Jonathan Linowes Jonathan Linowes
Profile icon Jonathan Linowes

Table of Contents (15) Chapters

Preface 1. Virtually Everything for Everyone 2. Understanding Unity, Content, and Scale 3. Setting Up Your Project for VR 4. Using Gaze-Based Control 5. Interacting with Your Hands 6. Canvasing the World Space UI 7. Teleporting, Locomotion, and Comfort 8. Lighting, Rendering, Realism 9. Playing with Physics and Fire 10. Exploring Interactive Spaces 11. Using All 360 Degrees 12. Animation and VR Storytelling 13. Optimizing for Performance and Comfort 14. Other Books You May Enjoy
Optimizing for Performance and Comfort

As we've mentioned throughout these chapters and projects, the success of your VR app will be negatively impacted by any discomfort your users feel. It is a fact that VR can cause motion sickness. The symptoms of motion sickness include nausea, sweating, headaches, and even vomiting. It can take hours – perhaps an overnight sleep – to recover. In real life, humans are susceptible to motion sickness: riding a roller coaster, a bumpy airplane, a rocking boat. It's caused when one part of your balance-sensing system thinks your body is moving but other parts don't.

In VR, this could occur when the eyes see motion but your body doesn't sense it. We've considered ways you can design your VR apps to avoid this. With locomotion, always give the user control over their first-person movement. Try to avoid riding-the-rails experiences and especially avoid...

Technical requirements

To implement the projects and exercises in this chapter, you will need the following:

  • A PC or Mac with Unity 2019.4 LTS or later, the XR plugin for your device, and the XR Interaction Toolkit installed
  • A VR headset supported by the Unity XR platform

You can access or clone the GitHub repository for this book (https://github.com/PacktPublishing/Unity-2020-Virtual-Reality-Projects-3rd-Edition-) to optionally use the following assets and completed projects for this chapter:

  • The asset files for you to use in this chapter are located in UVRP3Files/Chapter-13-Files.zip.
  • All the completed projects for this book can be found in a single Unity project atUVRP3Projects.
  • The completed assets and scenes for this chapter can be found in the UVRP3Projects/Assets/_UVRP3Assets/Chapter13/folder.

Using the Unity Profiler and Stats windows

Optimizing can be a lot of work, and there is a learning curve to get the hang of it. The good news is that it can be accomplished incrementally. Tackle the more obvious, bigger bang-for-their-buck things first. You can accomplish a lot with little or no visual degradation after a bit of experimentation. The UnityEditorincludes two built-in tools that can be used to assess performance: theStatswindow and theProfilerwindow, both of which I will introduce in this section.

The Stats window

The Stats window shows real-time rendering statistics when you press Play in the Unity Editor. Reviewing and understanding these statistics is your first line of call when it comes to evaluating and improving the performance of your app, and it can help you decide which optimization strategies, including those covered in this chapter, to tackle first. In theGamewindow, enableStats by pressing the Stats button. The output of doing this can...

Optimizing your art

The one thing that you have the most control over in your project is the content of your scenes. And sometimes, it's these very same intentionally creative decisions that have the greatest negative impacts on performance. Maybe you want hyper-realistic graphics with high-fidelity sound because its gotta be so awesome! Realizing you must dial that down may constitute a difficult design compromise. However, it's also likely that, with a little creative thinking and experimentation, you can achieve (nearly) identical visual results with much better performance.

"Quality" is not only how it looks, but also how it feels. Optimizing for user experience, including high frame rates and low latency, is as fundamental a design decision as visual quality.

In general, try to minimize the number of vertices and faces in your model's meshes. Avoid complex meshes. Remove faces that will never be seen, such as the ones inside of solid...

Optimizing your scene with static objects

Another way of optimizing your scene is to let Unity pre-compute a lot of the processing work in advance rather than at runtime. You can do this by informing Unity that specific objects will not change or move in the scene. This is accomplished by defining these game objects as static and then baking them into specific Unity system contexts, including lighting, occlusion, batching, navigation, and reflection probes. In the top-right of the Inspector window for each game object is a Static checkbox that can be used to set the object to Static for all Unity systems that can use it. Alternatively, you can choose the down arrow to select the static setting for individual systems, as shown in the following screenshot:

Ordinarily, if you're going to make an object Static, go ahead and check Everything, unless you know you need to refine it. The specific Static flags are as follows:

    ...

Optimizing the rendering pipeline

There are a number of important performance considerations that are specific to how Unity does its rendering. Some of these may be common for any graphics engine. Recommendations will vary, depending on your target platform (for example, desktop VR versus mobile VR), your render pipeline (for example, Universal Render Pipeline versus High-Definition Render Pipeline), and Project Quality settings. There are many articles on the internet offering recommendations on which settings to use to optimize your VR apps, and it's not unusual for someone's advice to contradict that of someone else. Here are some good ones:

  • In GraphicsProject Settings, select the render pipeline (RP) settings object for the project. This may have been set up by default when you chose a Project Template from Unity Hub when the project was first created.
  • In your chosen RP settings object (for example, UniversalRP-HighQuality versus UniversalRP...

Optimizing your code

Another area prone to performance problems and ripe for optimization is your C# script code. Throughout this book, we have used various coding best practices, without always explaining why. (On the other hand, some examples in this book are not necessarily efficient, in favor of simplicity and explanation). InChapter 9,Playing with Physics and Fire, for example, we implemented an object pool memory manager to avoid repeatedly instantiating and destroying game objects that cause memorygarbage collection(GC) issues, which, in turn, slows down your app.

In general, try to avoid code that repeats a lot of computation over and over. Try to pre-compute as much work as you can and store the partial results in variables. At some point, you may have to use a profiling tool to see how your code is performing under the hood. If the Profiler indicates that a large amount of time is spent in the scripts that you've written, you should consider another way...

Runtime performance and debugging

Graphics hardware architectures continue to evolve toward a performance that benefits rendering pipelines for virtual reality and 3D graphics. VR introduced requirements that weren't very important for traditional video gaming just a few years ago. Latency and dropped frames (where rendering a frame takes longer than the refresh rate) took a back seat to high-fidelity AAA rendering capabilities. VR needs to render each frame in time and do it twice: once for each eye. Driven by the requirements of this emerging industry, semiconductor and hardware manufacturers are building new and improved devices, which will inevitably impact how content developers think about optimization.

That said, you should develop and optimize for the lower specs that you want to target. If such optimizations necessitate undesirable compromises, consider separate versions of the game for high- versus low-end platforms. VR device manufacturers have started...

Summary

Latency and low frames-per-second rates are not acceptable and can cause motion sickness in VR. We are bound by the capabilities and limitations of the hardware devices we run on and their SDKs. In this chapter, we dove into some of the more technical aspects of making great VR by considering four separate areas that affect performance: the artwork, the scene, the rendering pipeline, and the code. This was a survey of the profiling and analysis techniques you can use and suggestions on how to address performance problems. This is no way a prescription for your own specific project, nor is this a complete treatment of this deep topic. This also gets into system architecture and engineering problems that may not be everyone's forte.

We started this chapter by introducing the built-in Unity Profiler and Stats windows, our primary weapons in this battle. To illustrate the impacts of designing models and materials, we built a scene with 1,000 high-poly Mememan...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Unity 2020 Virtual Reality Projects - Third Edition
Published in: Jul 2020 Publisher: Packt ISBN-13: 9781839217333
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.
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 $15.99/month. Cancel anytime}