Improving Game Visuals with Unity’s HDRP
Improve your game visuals and take them up by several notches using the High Definition Render Pipeline from Unity. By Wilmer Lin.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Improving Game Visuals with Unity’s HDRP
35 mins
- Getting Started
- Exploring the Level
- Understanding HDRP
- Adding Some Visual Flair
- Understanding Environment Lighting
- Adding a Sky and Fog Volume
- Understanding the Volume Framework
- Understanding Overrides
- Setting the Physically Based Sky
- Setting Exposure and Light Emission
- Understanding Exposure
- Understanding Light Emission
- Adding More Volume Overrides
- Setting Lightmapping and Global Illumination
- Understanding Global Illumination
- Baking Lightmaps
- Debugging the Render Pipeline
- Adding Volumetric Fog
- Understanding Volume Settings
- Understanding Light Settings
- Adding Lights
- Exploring a More Complex Scene
- Understanding the Light Explorer
- Where to Go From Here?
Adding Some Visual Flair
Going back to the Daylight scene, notice that a single Directional Light under Lighting is active. Rename it Sun_DirectionalLight.
Now, swing the light direction, so it enters from the window to the right. Adjust the rotation to (X: 27, Y: -79, Z: 0).
Turn on the light’s shadows. Check Enable under the Shadows component.
To improve the shadow map resolution, switch the Resolution to Ultra. The shadow edges sharpen and become less blurry.
Raking the shadows across the concrete blocks makes for a more dynamic composition. Diagonal lines help draw the viewer’s eye into the scene.
Understanding Environment Lighting
Currently, the scene has a bluish cast. This stems from some existing environmental lighting. In the Scene view, three main colors represent the outer boundaries of the world:
- A dark earthy ground color
- A brighter, white horizon
- A blue sky
The source of the color is DefaultHDRISky inside HDRPDefaultResources.
Double-click the image to open a preview. It consists of six smaller 128 × 128 images, stitched into one larger 768 × 128 EXR file. EXR is a high-dynamic range format. It contains a wider range of color and contrast than a typical image file.
How do you generate an HDRI?
[spoiler title=”How do you generate an HDRI?”]
A high-dynamic range image, or HDRI, merges several exposures from a digital camera into a special file format. The resulting image contains detailed information about the actual lighting conditions when photographed. Unity can then use this HDRI to approximate the environment lighting in your scene.
Want to shoot your own HDRIs? Follow these guidelines.
If you don’t want to make your own, Unity also provides an excellent HDRI Pack in the Asset Store to help you get started.
Many sites like HDRI Haven also offer free or low-cost HDRIs suitable for use within Unity.
[/spoiler]
How do you generate an HDRI?
[spoiler title=”How do you generate an HDRI?”]
A high-dynamic range image, or HDRI, merges several exposures from a digital camera into a special file format. The resulting image contains detailed information about the actual lighting conditions when photographed. Unity can then use this HDRI to approximate the environment lighting in your scene.
Want to shoot your own HDRIs? Follow these guidelines.
If you don’t want to make your own, Unity also provides an excellent HDRI Pack in the Asset Store to help you get started.
Many sites like HDRI Haven also offer free or low-cost HDRIs suitable for use within Unity.
[/spoiler]
The Texture Shape is set to Cube in the Import Settings.
Unity basically unwraps the cubemap and projects it onto the interior of a sphere. Drag the preview window to rotate the projection. Adjust the -/+ slider to visualize the bracketed exposures.
This HDRI sky sphere creates the illusion of the ground, horizon, and sky.
During the rendering process, light rays bounce around the world. Some of these rays return and strike the scene geometry. Each such reflection transfers a little bit of color from the HDRI sphere. This environment lighting and reflection creates the general bluish tint.
In this particular case, you’ll swap out the default HDRI to change the ambient color.
Adding a Sky and Fog Volume
Now, you’ll add some realism to the level using the Volume framework.
Understanding the Volume Framework
Unity uses the Volume framework to control aspects of the pipeline. An active Volume currently works as the default source of environment lighting.
Return to Edit ▸ Project Settings and locate the HDRP Default Settings tab. The Default Volume Profile Asset is set to VolumeGlobal.
Click New to create a custom Volume profile. This generates an asset called DefaultVolumeSettingsProfile, which is added to the HDRPDefaultResources folder.
In the Scene view, the colored HDRI environment disappears. The Game view, meanwhile, becomes extremely stark. It’s completely black and white, lit only by the direct rays from Sun_DirectionalLight.
Surfaces in the path of direct sunlight turn white. The light doesn’t bounce and scatter as you would expect in real life.
The current direct lighting strikes a surface and stops. Without indirect or bounced lighting, everything just looks unnaturally black.
You can fix that with some environment lighting.
Right-click in the Hierarchy to create a Volume ▸ Sky and Fog Volume. Now everything turns bright white. Don’t panic! This is just temporary. Parent this to the Lighting transform to stay organized.
It’s hard to see anything, so adjust the light intensity as a stopgap fix. Select the Sun_DirectionalLight. Find the Light component and locate Emission. Drag the Intensity down to something small, like 40 lux.
The blue cast disappears. The Game view now sports a warmer ambient light.
In the Scene view, the surrounding world changes color. The ground turns into an earthy yellow-brown, while the sky becomes a silvery light blue.
Understanding Overrides
Select Sky and Fog Volume. The Volume component allows you to influence the camera render with a series of overrides. Each override controls one part of the pipeline, giving you fine-level control of the rendered output.
Note that the Mode is set to Global. This means the component affects the entire scene. Weight and Priority help decide priority when more than one Volume is active.
Nested below the Volume component are three overrides:
- Visual Environment: This override determines what type of sky appears in the background. The default is Physically Based Sky, a procedurally generated environment. You can also choose a simple Gradient color or replace this with a photographed HDRISky.
- Physically Based Sky: This override simulates light dispersing through the atmosphere. It reproduces both Rayleigh and Mie scattering.
- Fog: This recreates thick, cloudy air that hangs close to the ground. The fog density attenuates as it rises upward and moves away from camera.
Unity stores all the Volume overrides in a Profile asset. Be careful! Any changes you make are saved immediately to disk.
Select the Sky and Fog Settings Profile in the project window. This is located in the RM/Scenes/Daylight folder.
Rename it to Day Settings Profile. You can have more than one Profile in the same scene. Name each one descriptively to tell them apart.
Now, modify the current Profile to the Day Settings Profile.