Forward and Deferred rendering
The High Definition Render Pipeline (HDRP) allows you to render Lit Materials using either Forward or Deferred rendering. You can configure your Unity Project to only use one of these modes, or allow it to use both and switch at runtime on a per-Camera basis.
Each rendering path uses a different set of steps to calculate lighting and draw objects. Which rendering path you choose affects the performance of your game and lighting options.
- Forward rendering: HDRP draws each object one by one. For each object, HDRP checks every light that affects it to calculate how the object looks.
- Deferred rendering: HDRP first renders information about every object into multiple buffers. Then in a later ('deferred') step, HDRP draws each screen pixel one by one by combining the information from the buffers.
Using Forward or Deferred rendering
Before you use forward or deferred rendering in your Unity Project, you must make sure your HDRP Asset supports them.
To set the default support for forward or deferred rendering in your Project:
- Select your HDRP Asset in the Project window to view it in the Inspector.
- Go to Rendering > Lit Shader Mode.
- Select one of the following Lit Shader modes:
Lit Shader Mode | Description |
---|---|
Forward | HDRP calculates the lighting in a single pass when rendering each individual GameObject. |
Deferred | HDRP renders the Material properties of every GameObject visible on screen into a GBuffer. HDRP then processes the lighting for every pixel in the frame. |
Both | Use the Frame Settings to change between Forward and Deferred rendering mode on a per Camera basis. Selecting this increases Project build time. |
If you select Both, you can set the rendering mode at runtime for each Camera individually. For example, you can use Forward mode for a Planar Reflection Probe and then render your main Camera using Deferred mode.
To override the rendering mode for a specific Camera:
- Select the Camera in the Hierarchy window to view it in the Inspector
- Go to Rendering and enable Custom Frame Settings.
- Go to the Rendering section and enable Lit Shader Mode. You can use this to change the Lit Shader Mode for this Camera.
- Select the rendering mode you want this Camera to use.
Selecting a Lit Shader Mode
To decide if you want to use Forward or Deferred mode, consider the level of quality and performance you want for your Project. Deferred rendering in HDRP is faster in most scenarios, such as a Scene with various Materials and multiple local Lights. Some scenarios, like those with a single Directional Light in a Scene, can be faster in Forward rendering mode. If quality is more important than performance for your Project, use Forward rendering mode for better quality rendering.
HDRP enforces Forward rendering for the following types of Shaders:
- Fabric
- Hair
- AxF
- StackLit
- Unlit
- Lit Shader with a Transparent Surface Type
If you set the Lit Shader Mode to Deferred in your HDRP Asset, HDRP uses deferred rendering to render all Materials that use an Opaque Lit Material.
Forward and Deferred rendering both implement the same features, but the quality can differ between them. This means that HDRP works with all features for whichever Lit Shader Mode you select. For example, Screen Space Reflection, Screen Space Ambient Occlusion, Decals, and Contact Shadows work with a Deferred or Forward Lit Shader Mode. Although feature parity is core to HDRP, the quality and accuracy of these effects may vary between Lit Shader Modes due to technical constraints.
Differences between Forward and Deferred rendering in HDRP
Feature | Forward Rendering | Defferred |
---|---|---|
Normal shadow bias | HDRP uses the geometric normal (the vertex normal) of the Material for shadow bias, so Forward Rendering produces fewer shadow artifacts. | HDRP uses the pixel normal of the Material for shadow bias, so Deferred Rendering produces more shadow artifacts. |
Emissive Color | Ambient Occlusion doesn't affect Emissive Color. | Ambient Occlusion affects Emissive Color due to technical constraints. |
Ambient Occlusion | HDRP applies the minimum amount of Ambient Occlusion and Screen Space Ambient Occlusion to Lightmaps, Lightprobes, and Screen Space Global Illumination and Ray-traced global Illumination. This results in correct darkening. | HDRP applies Ambient Occlusion on Lightmaps, Light Probes, and the Screen Space Ambient Occlusion effect. This results in incorrect darkening. |
Material Quality | There is no compression, so there are no compression artifacts. | HDRP compresses Material properties, such as normals or tangents, in the GBuffer. This results in compression artifacts. |
Depth Prepass | HDRP always renders a depth prepass, which outputs a depth and a normal buffer. | A depth prepass is optional in Deferred mode if you aren't using Decals. |
Normal Buffer | HDRP updates normal buffers after the decal DBuffer pass. HDRP uses the normal buffer for Screen Space Reflection and other effects. | N/A |
Build time
The build time for an HDRP Project may be faster when using either Forward or Deferred rendering. The downside of choosing a Lit Shader Mode of Both is that it increases the build time for the Player substantially because Unity builds two sets of Shaders for each Material, one for Forward and one for Deferred. If you use a specific rendering mode for everything in your Project, you should use that rendering mode instead of Both, to reduce build time. This also reduces the memory size that HDRP allocates for Shaders.
Tile and cluster rendering
HDRP uses tile and cluster rendering to speed up lighting calculations compared to the slower multi-pass lighting used in the Built-In Render Pipeline.
In tile and cluster rendering, the render pipeline subdivides rendering into the following:
- Tiles, which are small square 2D sections of the display.
- Clusters, which are 3D volumes inside the camera frustum.
For each tile or cluster, the render pipeline lists which lights affect it, then calculates the lighting in one pass using only the lights in the list.
HDRP usually uses tile rendering for opaque objects and cluster rendering for transparent objects.