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
Lighting, Rendering, Realism

Up to now, we've focused on the mechanics of developing interactive 3D scenes, starting with understanding 3D coordinates and scale, to interacting with your gaze and your hands, then displaying text and user interface (UI) elements, and finally, moving through the scene with locomotion and teleportation. In this chapter, we consider a different yet equally important aspect of your virtual reality (VR) project—the visual fidelity of your scene. We will examine many of Unity's powerful tools for lighting, rendering, and realism.

Rendering and lighting are complex topics, broad and deep. It can take years of experience and artistic skills to master the quality we have come to expect in AAA video games and Hollywood movie productions. Unity is amazing because it provides many simple, easily accessible tools for getting your scenes to look very good even if you have limited experience...

Technical requirements

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

  • PC or Mac with Unity 2019.4 LTS or later, an XR Plugin for your device, and the XR Interaction Toolkit package 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 assets and completed projects for this chapter, as follows:

  • All completed projects in this book are in a single Unity project at UVRP3Projects.
  • The completed assets and scenes for this chapter are in theUVRP3Projects/Assets/_UVRP3Assets/Chapter08/folder.

Lighting and rendering strategies

Lighting your scenes starts with your project's requirements and your own decisions about the look and style you are aiming for. Do you want high-quality realism or simpler geometric rendering? Do you want lifelike objects or cartoon-like graphics? Are you lighting an outdoor scene or an indoor one? Just as important, you also need to ask yourself what are the primary target platforms, especially: is it mobile, desktop, or console? At some point in your projects, before creating the final assets and lighting, you need to figure out your lighting strategy, as Unity recommends:

Altering your lighting strategy late in development has a high impact on your workflow. Taking the time to get this right before you enter production saves time overall, and allows you to achieve better performance and higher visual fidelity.

In this section, I'll try to break down the different types of lighting sources and settings you can use...

Setting up our demo scene

To demonstrate lighting and rendering in Unity, we'll start the project for this chapter with an existing scene and observe the effect of removing or modifying certain lighting settings and GameObjects. When you start a new project from the Unity Hub using the Universal Render Pipeline template, it contains a default sample scene named SampleScene. For this chapter, we'll decompose the SampleScene rather than build up a new scene. (There is a risk that the SampleScene is subject to change in the future, so please adapt the instructions herein as needed.)

In the Scene, we'll create a tabbed menu panel with which you can interact within VR. I'm going to attach it to the LeftHand Controller, but if you prefer to place it as a dashboard panel in world space, feel free to do that. First, we'll adopt this SampleScene and add a VR Rig, then we'll disable lightmap baking so we can change lighting settings at runtime, and...

Using environment lighting

The Environment lighting settings offer the ability to specify contributors to environmental illumination including a Skybox and Fog. A Skybox is a panoramic texture representing the sky that is drawn behind all objects in a scene as if at a far distance. We used the Wispy Skyboxes, for example, in previous chapters, and Skyboxes are discussed in more detail in Chapter 11, Using All 360 Degrees. More than rendering how the sky looks, with the Environment Lighting settings opened (using Window | Rendering | Lighting | Environment), you can specify if and how much the Skybox texture contributes to the Global Illumination and set its intensity level, as shown in the following screenshot:

For more details on using these and other settings in this window, consider the following pages from the Unity Manual:

Using PBR materials and URP Shaders

3D objects can be rendered simplistic, such as a cube with flat-shaded faces, or very realistically, such as the same cube as a realistic wooden crate. This magic is performed with PBR materials and advanced Shaders.

A 3D object in Unity consists of a geometry mesh that defines the points, edges, and faces of the object, forming a surface that can then be rendered to appear as a solid object. Each object has a Renderer component that specifies the properties and behavior of this particular object rendered in the scene. It includes references to any Materials that will be applied to the object. A Material is an asset that specifies a specific Shader script that drives the actual work of drawing the object on the screen. You can learn more about all of this in the Unity Manual and Unity Learn sites, among many other resources. The following web pages provide more information:

  • Best Practices Guide: Making...

Using Light objects and Emission surfaces

For indoor and local lighting, you will want to add Light objects to your scene. These are GameObjects that are not rendered themselves as meshes but rather emit light in a specific pattern, such as a cone (for example, a Spot light), sphere (for example, a Point light), or unidirectionally (for example, a Directional light). Also, you can specify individual objects to illuminate from their inside by assigning Materials with Emission properties. For more information on designing and using light objects, see the following links:

Using Light Probes and Reflection Probes

For non-static GameObjects to receive global illumination, you need to have Light Probes distributed in the Scene. These provide high-quality lighting for moving (dynamic) objects. Light Probes are positions in the scene where information is captured about the light that is passing through the empty space in your Scene. This information is baked similar to lightmaps and then used when the scene is rendered at runtime to approximate the indirect light hitting dynamic objects, based on proximity to the Light Probes nearest to that object. For more information on Light Probes, see https://docs.unity3d.com/Manual/LightProbes.html and the corresponding subpages.

The difference between light probes and lightmaps is that while lightmaps store lighting information about light hitting the surfaces in your scene, light probes store information about light passing through empty space in your scene. - Unity Manual

A group of Light Probes...

Enhancing your scenes with post-processing effects

So, we've seen how the Render Pipeline can use environment lighting, PBR Materials, Light GameObjects, and Probes to render realistic views of your scene. But wait! There's more! You can add post-processing effects to the fullscreen camera buffer image before it appears on the screen. Post-processing effects are often used to simulate the visual properties of a physical camera and film. Examples include Bloom (fringe lighting extending the border of extremely bright light), Color Grading (adjusts the color and luminance of the final images, like an Instagram filter), and Anti-aliasing (removing jaggy edges). You can stack a series of available effects that are processed in sequence.

For example, the Vignette effect darkens the edges of the image and leaves the center brighter. In VR, during a fast-paced scene (such as a racing game or roller coaster), or when teleporting, using a Vignette can help reduce motion...

Summary

In this chapter, we explored how to create visual realism in your VR scenes using environmental lighting, Light GameObjects, emissive materials, post-processing, and other tools included with Unity. We started by walking through a lighting strategy for configuring and enhancing your scenes, using decision trees and best practices suggested in the Unity Best Practices Guides. Then, using a sample scene, you created a menu palette with control panels for manipulating various lighting settings in the scene at runtime, while in VR.

You learned about the Lighting settings window, Global Illumination baking, and the Environment light settings, adding UI controls to modify the Skybox and Fog contribution to lighting. Then, you learned about PBR materials for creating realistic 3D objects in the scene, adding UI controls to modify the Material properties of various texture maps. Next, you learned how to use Light GameObjects and Emission Material properties to add local...

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}