安静如鸡

  • Home
  • About Me
  • Contact Me
  • 东京女子篮球活动记录
一个博客
  1. 首页
  2. Tech
  3. 正文

【WIP】URP Scriptable Renderer Feature

2024-03-08 0人点赞 0条评论

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@14.0/manual/renderer-features/create-custom-renderer-feature.html

记录一下在按照步骤实现上面教程的时候遇到的问题和想到的一些事情。

URP提供了Scriptable Renderer Feature可以自定义渲染的方法,或者Post-Processing效果

主要分为两个部分,
一个部分是继承ScriptableRenderPass,主要用来定义如何渲染,渲染的方法等等。
另一个部分是ScriptableRendererFeature,主要是在Render设置上增加component以及从Inspector的component得到用户设置的参数,管理多个Pass,以及定义Pass在什么时候实施。
下图部分的Settings和Shader都是在RendererFeature里定义的

关于Pass实施可以injection的几个时间点:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@14.0/manual/customize/custom-pass-injection-points.html

SwapBuffer
在把渲染效果反映出来的时候在URP12之前一直需要用户自己去管理buffer,

  1. 先准备一个临时的renderTexture
  2. 在原来的Texture上进行渲染,结果储存到临时RendererTexture上
  3. 然后把临时的RenderTexture反过来渲染到原来的Texture上
  4. 释放临时RenderTexture

URP12之后出现了SwapBuffer的功能,可以不需要考虑太多因素,直接做一个渲染。

public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
    var cmd = CommandBufferPool.Get(ProfilerTag);
    Blit(cmd, ref renderingData, material);
    context.ExecuteCommandBuffer(cmd);
    CommandBufferPool.Release(cmd);
}
C#

但是在URP这个sample里好像并没有用到Swapbuffer,在Blit的部分分成了两块

       // Blit from the camera target to the temporary render texture,
        // using the first shader pass.
        Blit(cmd, cameraTargetHandle, textureHandle, material, 0);
        // Blit from the temporary render texture to the camera target,
        // using the second shader pass.
        Blit(cmd, textureHandle, cameraTargetHandle, material, 1);
C#

sample使用的Shader有两个Pass,第一个是水平方向模糊,第二个是垂直方向的模糊,这样先把原始的texutre通过水平模糊Pass渲染到临时的textureHandle,再从textureHandle通过垂直方向的Pass渲染到cameraTargetHandle

也可以利用Swapbuffer来实现。

        Blit(cmd, ref renderingData, material, 0);
        Blit(cmd, ref renderingData, material, 1);
C#

这样既不用设置临时的textureHandle,也不用去管它什么时候释放,cameraTargetHandle也没必要声明了

参考:
https://light11.hatenadiary.com/entry/2022/06/30/191707

标签: 暂无
最后更新:2024-03-08

Ellison

什么都懂点,什么都不精。属于混吃等死,享受生活,过一天算一天的享乐主义。喜欢电影,阅读,以及游戏和美食。

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2024 安静如鸡. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang