📝 Custom render passes in Unity

1-minute read

Introduction

Since the introduction of Unity's Scriptable Render Pipeline in 2018, you can create your own custom render passes and inject them into the render pipeline. Since the documentation on them is still lacking, I created this basic template pass that could function as boilerplate code for your own passes and effects. The code is heavily commented for those who want additional information about what's going on.

This example pass simply blurs the screen using a 2-pass box blur shader. You can control the blur strength and set the downsampling factor. The code is tested to work with URP 12 in Unity 2021.2 but should also work on older versions. The API for scriptable render passes has changed a bit over the years, but the logic is the same.

Workings and Usage

The render passes uses the camera color buffer and a temporary buffer. Then it performs these 2 steps:

  1. Blit from color to temporary (blurring vertically in the process)
  2. Blit from temporary to color (blurring horizontally in the process)

After these 2 steps you ended up with a box-blurred camera color buffer.

To use this pass, simply add it as a renderer feature in your Forward Renderer Data asset.

Adding the custom pass.
75%

Scriptable Renderer Feature

Scriptable Render Pass

Box Blur Shader