Hi and welcome to Decompiled Art articles!
Thought this series of blogposts we'll create mobile-oriented rendering pipeline based on Unity's built-in Scriptable Rendering Pipeline API.
Ill try to make it simple and practical so you can implement and extend provided code & its features for your project needs. Thanks so much, hope it'll be a fun journey, let's s begin.
First things first, what is Scriptable Rendering Pipeline (SRP for short) and why you should (at least) consider using it?
Rendering Pipeline at its origin (not only within Unity) is a set of rules to determine what has to be rendered and what set of features should be applied to render a single frame. There are lots of possible render features could be applied, but to name a few and for you to better understand, here're some examples: lights, shadows, opaque/transparent shadings, post-processing, etc.
More information on what SRP is & what it does from Unity:
https://docs.unity3d.com/Manual/ScriptableRenderPipeline.html
Project setup
Open Unity Hub and create new project with selected template: 3D Core. For this series I'll be using Unity 2021.3.3f1.
We will not be configuring and explore existing SRP templates (URR, HDRP) but rather will build our own from the ground up
Next, depending on your project needs, create a new scene. Then create several objects with different shading features. We'll start pretty simple. I've created four materials (2 per lit and unlit shading)
Next we need to create a new RenderPipelineAsset. This asset behaves like main entrance point to determine how rendering should be configured for your project. It's also used to store various settings as interactive controls for Render Pipeline stages.
using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(menuName = "Rendering/RP/CustomRPAsset")]
public class CustomRPAsset : RenderPipelineAsset
{
protected override RenderPipeline CreatePipeline()
{
return null;
}
}To check that everything is working properly, create new RenderPipelineAsset and assign it as project's RenderPipelineAsset.
Confirm changing Render Pipeline.
Once you assigned RenderPipelineAsset to Scriptable Render Pipeline Settings field, you should check are there any errors. If not, you'll end up with just blank black.
That's totally fine cause we have nothing specified to configure our own Render Pipeline.
Next step is to create RenderPipeline script itself. Create new C# script...
using UnityEngine;
using UnityEngine.Rendering;
public class CustomRP : RenderPipeline
{
protected override void Render(ScriptableRenderContext context, Camera[] cameras)
{
}
}
Rather than returning null (within out custom RenderPipelineAsset) we now can return newly added RenderPipeline.
using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(menuName = "Rendering/RP/CustomRPAsset")]
public class CustomRPAsset : RenderPipelineAsset
{
protected override RenderPipeline CreatePipeline()
{
return new CustomRP();
}
}A good practice is also to have a dedicated control over each camera rather than rendering all existing once with same RenderPipeline properties. To do that we need to create a new class for Custom Camera Renderer.
using UnityEngine;
using UnityEngine.Rendering;
public class CustomCameraRenderer
{
private ScriptableRenderContext _context;
private Camera _camera;
public void Render(ScriptableRenderContext context, Camera camera)
{
_context = context;
_camera = camera;
}
}Now (within CustomRP Rendering Pipeline) we can iterate through each available camera by providing existing context and cameras array to public Render() method created earlier. Don't forget to create an instance of custom Camera Renderer.
using UnityEngine;
using UnityEngine.Rendering;
public class CustomRP : RenderPipeline
{
private CustomCameraRenderer _renderer = new CustomCameraRenderer();
protected override void Render(ScriptableRenderContext context, Camera[] cameras)
{
foreach (var camera in cameras)
{
_renderer.Render(context, camera);
}
}
}At this point you should have three scripts that are responsible for creating CameraRenderer, RenderPipeline and RenderPipelineAsset.
Also, you can dock FrameDebugger and take a look at its stats. Our pipeline is working... but nothing happens.
You're good to go and have everything set up for implementing your RenderPipeline features. Which we'll do in the next chapter.
Hope you've enjoyed with provided info and thanks a lot! Stay tuned!
Support Decompiled Art on Patreon
Support Decompiled Art with Ko-fi
***
FOLLOW AND CHECK FOR UPDATES:
Decompiled Art YouTube
Decompiled Art Instagram
Decompiled Art Twitter
Decompiled Art Facebook
***











