-
Notifications
You must be signed in to change notification settings - Fork 86
Custom Renderer Features
zilch edited this page Jan 24, 2021
·
1 revision
在URP里,可以通过扩展RendererFeatures
来实现自定义的Pass。
-
新建
PostProcessingPass
,继承ScriptableRenderPass
public class PostProcessingPass : ScriptableRenderPass{ private const string CommandBufferTag = "CustomPostProcessing"; public PostProcessingPass(){ //通过设置renderPassEvent,来控制该pass在何时被渲染。 this.renderPassEvent = RenderPassEvent.AfterRenderingTransparents; } ///在Execute里可以构造Pass渲染指令 public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var cmd = CommandBufferPool.Get(CommandBufferTag); try{ // 调用渲染函数 Render(cmd, ref renderingData,context); // 执行命令缓冲区 context.ExecuteCommandBuffer(cmd); }finally{ // 释放命令缓存 CommandBufferPool.Release(cmd); } } }
-
新建
PostProcessingFeature
,继承自ScriptableRendererFeature
public class PostProcessingFeature : ScriptableRendererFeature { private PostProcessingPass _pass; //在此处初始化 public override void Create(){ _pass = new PostProcessingPass(); } //在此处将自定义的Pass加入到渲染管线中 public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData){ //设置渲染对象 _pass.ConfigureTarget(renderer.cameraColorTarget); //将Pass加入到渲染管线 renderer.EnqueuePass(_pass); } }
继承自
ScriptableRendererFeature
后需要实现两个函数,其中-
OnCreate
用于初始化 -
AddRenderPasses
则用于将自定义的Pass加入到渲染管线中。
-
-
将
PostProcessingFeature
加入到渲染管线中- 选中
Settings/ForwardRenderer
- 在右侧面板点击
Add Renderer Features
即可添加
- 选中