In this video, we’re going to explore seven ways that you can optimize your Unity project
to get the best results out of Unity 2020 and the Universal Render Pipeline.
There are plenty of ways you can optimize for better performance and better visual fidelity
but each is going to be highly dependent on the nature of your project, so make sure that
as you make changes you profile and test to confirm that performance is actually improving.
Manage Your Lighting
The Universal Render Pipeline has been built with optimised realtime lighting in-mind,
in the URP Forward Renderer you can have up to 8 realtime lights per object and up to
256 realtime lights per-camera on Desktop, and 32 realtime lights per camera on Mobile
and Switch.
The Universal Render Pipeline also allows for configurable per-object light settings
inside of the pipeline asset for even more control over your lighting.
However, one of the best ways to improve the performance of your scene is to bake your
lighting wherever possible.
Realtime lighting can be expensive, and baking your lights can be a great way to gain back
performance.
Especially if the lights in your scene aren’t going to be moving.
The process of baking, essentially allows lighting data in your scene to be pre-rendered
into textures that are then re-projected onto the geometry in your scene.
By pre-rendering your lighting data to baked textures, you can save valuable rendering
time and increase the performance of your scene as the lighting textures can be batched
into a singular draw call and don’t need to continuously be calculated - this is especially
useful if your scene uses multiple lights.
Another great reason to bake your lighting is that it allows you to render bounced or
“indirect” lighting in your scene and improve the visual quality of your scene.
This is known as Global Illumination, and is a process that simulates rays of light
bouncing around your environment and illuminating other nearby objects with the bounced light
rays.
When baked, areas of shadow in your scene will receive the bounced light and will become
illuminated.
It can be subtle, but this technique spreads the light around your scene more realistically
and improves its overall appearance.
To get started baking your lighting, you first need to mark your lights as Baked.
You can do this by selecting the lights in your scene and choosing “Baked” from the
Mode dropdown.
Make sure that any geometry in your scene is marked as Static.
This will allow it to be included in the lightmapping calculations, and contribute towards the bounced
light from the Global Illumination.
It’s worth noting that, you can also change lightmapping settings on individual object
meshes, by selecting the game object in the inspector and adjusting the settings on the
Mesh Renderer in the inspector.
This can be a great way to improve baking times, as you can reduce the settings for
distant or smaller objects.
Once your scene is set up for baking, open the lighting window by choosing Window -> Rendering
-> Lighting and create a new Lighting Settings Asset.
Then set up your Lightmapping settings using the Progressive Lightmapper and choose Generate
Lighting.
When you’re setting up your lightmapping settings, you might find that it will take
a long time to bake.
It’s advisable to start with a low lightmap resolution and size while you’re iterating
on your scene during development.
Then, when you’ve finished working on your scene, gradually increase the resolution,
size and sample settings to something more suitable for your target appearance.
You’ll want to find a resolution that allows these settings to be no higher than they need
to be, as lower resolution and lightmap sizes will help lower the texture memory requirement.
Use Light Probes
Light Probes sample the lighting data in your scene during baking and allow the bounced
light information to be passed onto dynamic objects that may move or change such as characters
or vehicles.
This helps them to blend into, and feel more natural in, the baked lighting environment.
Here you can see the difference between how our character looks with and without light
probes active in our scene.
To add light probes into your scene, simply choose Create -> Light -> Light Probe Group.
Then position your probes into the scene and choose the edit light probes option.
We can then select a light probe and duplicate it using the button in the inspector or CTRL
+ D on our keyboard in windows, or CMD+D on Mac to begin positioning our probes.
Generally, it’s worth placing probes wherever there is a shift in lighting.
So, place them close to shadowed areas or areas where lighting colours change more frequently.
Then, just bake your lighting again to see the effect of your newly placed probes.
If you have auto-generate enabled in the Lighting Settings Panel, your scene should automatically
update to compensate for the probes.
Use Reflection Probes
The final way we can use lighting settings to optimise our scene is through the use of
reflection probes.
Reflection probes are a way of projecting parts of the environment onto nearby geometry
to create more realistic looking reflections in our scene.
By default, Unity will use the skybox as the reflection texture on your objects.
But, reflection probes allow your reflections to more closely match their surroundings.
Notice here how more of the lighting in our scene is reflected onto the edges of our objects
and smooth parts of our character.
To create reflection probes simply choose Create -> Light -> Reflection Probe.
Next, position and size your reflection probes into areas of your scene where reflections
are needed.
Then to bake your reflections, simply choose the Bake Reflection Probes setting in the
Lighting Window.
If auto-generate is enabled, Reflection Probes will be baked automatically.
Be sure to experiment with the resolution of your probes using the Resolution dropdown.
Higher resolutions will mean higher quality reflections, which are good for objects that
may be viewed close up.
However, if your camera is further away, lowering the resolution will help keep your scene optimized
by storing less information in memory.
Manage your Camera Settings
The Universal Render Pipeline includes ways to optimise your camera by disabling unwanted
renderer processes on your cameras.
This can be extremely useful if you’re targeting both higher end and lower end devices in your
project.
By disabling things like post-processing, shadow-rendering or depth-texture you can
remove any potentially expensive behaviours on lower-quality settings and increase performance.
Another great way to optimise your camera is through the use of Occlusion Culling.
By default, the camera in Unity will always draw everything within the camera’s view
frustum, including geometry that may be hidden behind walls or other objects.
Drawing Geometry is quite expensive and there’s no point in drawing objects that the player
won’t be able to see.
This is where Occlusion Culling can be extremely useful.
By baking Occlusion Data, Unity can ignore any parts of your scene which are blocked
from view of the camera and therefore increase performance by reducing the amount of scene
geometry being drawn per frame.
To enable Occlusion Culling in your scene, you’ll need to mark any geometry as either
occluder static or occludee static.
Once your geometry is marked, open the Occlusion Window by going to Window -> Rendering -> Occlusion
Culling.
Then, click Bake.
Now Unity will use the occlusion data when rendering and not render any geometry that
is within the Camera’s view frustum but blocked by another object.
This can be previewed in the Scene view during play mode by selecting a camera and enabling
the Visualisation Tab.
Manage your Render Pipeline Settings
The Universal Render Pipeline is designed to support deployment onto multiple target
platforms and devices.
For that reason, the Universal Render Pipeline Asset contains multiple settings that we can
control to increase and improve performance in our game.
You can view the Render Pipeline Asset by selecting it in the project window.
Or by choosing Edit -> Project Settings -> Quality and selecting the Render Pipeline Asset.
Each Quality Tier in the project can hold a different Render Pipeline Asset.
So, you can create different Render Pipeline Assets to customise the renderer settings
and control how your game performs at each Quality Tier.
Many of these settings will impact the overall performance and visual quality of your scene.
It is worth experimenting with them in order to get the best results for your project,
but generally if you’re looking to gain performance it is worth reducing shadow resolution
and distance as much as possible - as well as disabling any features your project isn’t
using such as the Depth Texture or Opaque Texture.
Similarly, enabling Dynamic Batching will tell the Universal Render Pipeline to automatically
batch any dynamic GameObjects into the same draw call if they’re sharing the same material
and can be batched.
So, if you have lots of dynamic objects in your scene, this can be a useful way to gain
some performance.
The SRP Batcher has been designed specifically for improved batching in the Universal Render
Pipeline.
If you’d like to read more on optimising your settings using Shader Stripping and the
SRP Batcher, we’ve posted a link in the description down below.
Use The Frame Debugger
Finally, for a better understanding of what’s happening during rendering of your scene you
can make use of both the Frame Debugger and the Profiler.
The Frame Debugger gives you a breakdown of all of the draw calls your game makes before
rendering the final image and can be a great way to figure out why certain frames are taking
longer to draw than others, or to help identify why your scene’s draw call count is so high
in the first place.
The Frame Debugger can be found by going to Window -> Analysis -> Frame Debugger.
When your game is playing, select the Enable button to get a breakdown of the scene at
each point in the rendering cycle.
This is also where you can see any Renderer Features you may have active in your Pipeline
Asset and identify the impact your custom features may be having on the rendering loop.
For more information on Renderer Features and how to use them, follow the link below.
Use the Profiler
Similarly, The Profiler is a great way to figure out how long your project takes to
complete a frame cycle.
It gives an overview of rendering, memory and scripting.
The profiler can help identify scripts that are taking a long time to complete and give
you an indication of potential bottlenecks in your code.
The Profiler can be found by going to Window -> Analysis -> Profiler.
When play-mode is active, the window will give you an overview of the overall performance
of your game.
You can also pause the live view and use the hierarchy mode to get a breakdown of the Time
taken to complete a single frame and each call Unity has made during that frame.
------------------------
These are just a few of the ways you can optimise your scene to increase both performance and
fidelity.
For more information on ways you can optimize your Project and for more information on the
Universal Render Pipeline, follow the link below.
Thanks for watching.