Were Excited About Unitys Scriptable Render Pipelines Heres Why Large

We’re Excited About Unity’s Script­able Render Pipelines: Here’s Why

 insights

Intro­duc­tion

Unity 2018 is finally here and with it comes several important new additions to your favorite toolset. The Job System, Progres­sive Lightmapper, and of course Script­able Render Pipelines (SRP), just to name a few.

Not only is Unity offering two main­tained Script­able Render Pipelines through their Package Manager and public GitHub, but they’ve also made available the means of devel­oping completely custom-tailored Pipelines yourself. Since I specialize in Rendering here at Schell Games, that last bit is really exciting. In this post, I’d like to talk about what SRP is and why this feature is going to be important for you and your Unity games moving forward.

What Are SRP, Exactly?

Script­able Render Pipelines are the new way to implement custom rendering in Unity. It is a collec­tion of C# scripts and Shaders that gives you, a Developer, unprece­dented control of how your game gets rendered. But moreover, SRP is about choice. When you build a specific type of game that has specific needs, you will inevitably make important choices. When it comes to rendering, these choices, more often than not, have the largest impact on perfor­mance.

For instance, a cinematic, photo-realistic, Third Person Action game targeting PC & Console at 30 frames per second (FPS) has a very different set of constraints than a Mobile VR game that needs to run at a solid 60 FPS on a phone. This is where SRP truly shines and where the built-in Renderer provided by Unity has suffered in the past.

In a way, SRP is a reboot of how we can think of rendering when it comes to Unity.

Games Made In Unity

At Schell Games we create diverse content on a variety of Platforms, each of these have unique rendering needs.

If you are targeting hardware with limited resources, you can signif­i­cantly reduce overhead caused by a one-size-fits-all renderer and focus on the bits that are the most important to your game. If you don’t rely heavily on precise per-pixel lighting effects, you don’t need to pay the perfor­mance cost for setting them up in the first place. This frees up resources to be spent on making your game look and play the best that it can!

Building a Script­able Render Pipeline: At a Glance

During the Public Beta phase of 2018.1, I decided to write my own SRP from scratch as an exercise to gain a better under­standing of what this new system can do. I’ve assembled some notes on what it takes and how it works.

The Render Pipeline Asset

Every­thing starts here. You build an Asset that serves as a hub for your Renderer’s global settings. This Asset is what gets assigned to your Project’s Graphics Settings in order to enable the SRP feature.

The Render Loop

Render Loop

A common Render Loop

The Render Pipeline Asset will generate a Render Pipeline instance when the Unity Engine requests it. This is where your Render loop is executed. The Render loop receives a Script­able Render Context, and all of the Cameras that will render this frame. In the Editor, this intro­duces some inter­esting cases for things like Inspector Previews and Thumb­nails because they all run on the same loop!

Script­able Render Context

The context object is where you’ll build up your render commands. This is where you will issue your commands to Draw Renderers, Shadows, and executing Graphics Commands.

Culling

You’ll only want to render things the Player will be able to see, and Unity makes this easy with Cull­Re­sults. You can specify custom Script­able Culling Para­me­ters, or simply grab them for the currently rendering Camera. This takes any Level of Detail (LOD) and Occlusion Culling data that may have been set up into account as well. The resulting data will be a collec­tion of visible Lights and Renderers for you to do with what you please.

Drawing

Rendering is still done in Passes, just like it has always been. But in the case of SRP, you can build as many custom Passes as you want. This allows for further filtering of your visible Renderers to be drawn as you see fit. There are other means of filtering this data as well, which exist across the Material and Renderer levels. This provides a robust API for customizing your Renderer, and has some added perfor­mance benefits when orga­nizing your loop. For instance, orga­nizing draw order by Shader complexity can save precious millisec­onds on Tile-Deferred GPUs.

Putting It Together

Ieytd Putting It Together

From Clear to a finished frame in ‘I Expect You To Die’

All together, a given SRP can be as simple or as complex as your target deems necessary. And this flex­i­bility is the true power of the feature. You can organize your render loop to be precisely what is needed and optimized for your target hardware without concern for any extra bloat that the Legacy Renderer provides. This combined with Unity’s new SRP Batcher gives you perfor­mance by default, which is always a plus.

The Benefits of SRP Moving Forward

As I’ve mentioned above, SRP is about choice. When you get to the point in your project that you’re making decisions about Rendering, you probably know what type of game you’re going to make. Here are some things to consider:

  1. Target Hardware. This is going to dictate what you’re ulti­mately capable of doing, so it should be the first thing to be consid­ered. Bleeding-edge Graphics tech­niques require more resources and often Graphics hardware features that aren’t widely supported.
  2. Game Type. A Mobile Match 3 game probably doesn’t need a Renderer capable of unlimited real-time per-pixel Lights. Dialing back the Graphics will not only provide a smooth expe­ri­ence, but will prolong battery life on your Players’ Mobile devices!
  3. Time and Effort. The more complex the Renderer, the more time and effort you will spend building and main­taining its features. Be sure to weigh this against what the feature will provide your Content Creators, even if you’re a single person team.

Previ­ously, before the intro­duc­tion of SRP, extending Unity’s Renderer to achieve custom effects was often limited, difficult, and sometimes downright infu­ri­ating. If a partic­ular hook into the Renderer wasn’t readily available, it could result in hours of work or worse if a bug was blocking you. Since SRP minimizes the core black box’ rendering code, the margin for error where show-stopping bugs can ruin your day has been greatly reduced. This is an invalu­able benefit.

Shader Stuff By Kwame

A ShaderGraph authored by one of our Effects Artists, Kwamé Babb

Finally, the addition of Shader­Graph, which is only supported through SRP is going to be life-changing for Content Creators. Artists and Designers will be able to author custom Shaders without having to learn how to program. This puts the power in the hands of the ones who can do the most with it. Your Content Teams not only want or need this, they deserve it.

How Do I Get Started?

Getting started is easy if you just want to pull in one of Unity’s provided SRP, and there are a couple avenues you can go right from within Unity.

Project Templates

If you’re creating a project from scratch, you can start with one of the new Project Templates from your Create Project Menu. It’s important to note here that these Templates may not neces­sarily bring in the latest and greatest’ version of the SRP Package.

Srp Project Template

The Package Manager

If you’re looking to upgrade an existing project and want to test if SRP is right for you, just open up the Package Manager and install the SRP package of your choice.

Srp Packet Manager

Next, you’ll need to generate a Script­ableRen­der­Pipeline asset in your Project, and assign it to the appro­priate slot at the top of your Graphics Settings Window, et voila! Now you’re cooking with SRP!

I should mention here that at this point, many of the Shaders used by Unity previ­ously will simply stop working. No worries there if you’re upgrading your project, there is a Material Converter to port built-in Materials to SRP. This won’t work with any custom or third-party and Asset Store packages by default, though, so some work may still be ahead of you.

Straight From the Source

If you’re at all like me, you’re going to want more control than Package Manager provides. In which case, get the direct source of SRP from the GitHub Project. In this case, you’ll need to clone the Repo into your Project’s directory and likely checkout a branch that corre­sponds with the version of Unity you’re on. At the point that I’m writing this, I am person­ally synced to the 2018.2 Branch.

Closing Thoughts

I am obviously very excited about the future of rendering in Unity and what the community will be able to achieve with this new and powerful tool. I am looking forward to using it to empower our Artists and help create amazing visual content here at Schell Games!

If you’re curious about the inner workings of SRP, I have a post on my personal Blog where I’ve kept running notes while devel­oping one from scratch, complete with source code!