How to Blit in URP

这篇博客讨论了在Unity的Universal Render Pipeline(URP)中如何进行Blit操作。建议优先使用SRPBlitter API,因为它更透明且与NativeRenderPass和RenderGraph兼容。然而,对于某些特定需求或优化,如移动平台的Load/Store动作,可以使用DrawMesh方法。cmd.Blit不应被使用,因为它可能导致兼容性问题,并可能在未来版本中被弃用。文章还提到了XR中的全屏Blit示例,并指出将更新文档和提供示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use SRP Blitter if what you need to do is available and implemented in that API, use the DrawMesh approach for any other cases, avoid cmd.Blit()

For historical reasons URP doesn't currently have a proper standard in terms of "how to Blit".
I agree that this is very confusing, and it is something we are trying to document better as we speak.
This is an important ongoing discussion at the moment, since reviewing the state of our blits is also an important preparation step for some core changes in URP, better NativeRenderPass and RenderGraph support. Following these best practices early on existing projects should also make your life easier when upgrading to the next URP releases.

I'll try to do a quick summary here, but you should expect documentation coming soon:

1) cmd.Blit() should not be used. The main reason is that it is a bit of a "black box", since it contains a lot of built-in logic, in terms of changing states, binding textues and setting render targets. All of these are happening under the hood, so not transparently from an SRP point of view, which can cause some issues. Other big issues with cmd.Blit(): it "breaks" NativeRenderPass and RenderGraph compatibility, so any pass using cmd.Blit will not be able to take advantage of these. It also doesn't work well in XR. Its usage might also be deprecated in future URP versions.

2) the same applies obviously to any utilities/wrappers relying on cmd.Blit() internally, so for example RenderingUtils.Blit should be avoided as well

3) The current How to perform a full screen blit in Single Pass Instanced rendering in XR is a good example to follow. Under the hood cmd.Blit() does pretty much the same, except in this case everything is handled at the SRP level, which is the way to go. I think the fact that the page is mentioning XR is a bit confusing, since this is a perfectly valid way of doing blit on all platforms. So I am looking at updating that page. It is also in need of some sample code changes* since in the current state it doesn't work anymore on 22.1, because of the recently introduced RTHandles support.

4) The SRP Blit API "to use" is Core Blitter: it is already used by other pipelines, and refactoring our existing passes so that they use it instead of cmd.Blit is in our short-term roadmap. This might also include modifying and improving the Blitter API to accomodate any URP requirements. So expect some changes soon in this area

on top of the RTHandles availability issue, which make SRP Blitter not usable on versions < 22.1, there are still scenarios where you might be better off writing your "custom blit" using DrawMesh, like the how-to page shows.

SRP Blitter will be improved in the future to facilitate URP adoption, but for now for example you are unable to do things like setting explicitly Load/Store actions if you are optimizing for mobile.
With DrawMesh you could also write easily generic full screen quad renderers, which don't necessaily need to blit a source texture to a destination one: as an example, a very common pattern currently for post processing effect doing similar stuff (i.e. ColorGradingLUT) is to call cmd.Blit(null, RT). This is not the best use of blit and works much better with a simple draw to full screen quad mesh.

Other examples of useful custom blit implementation could be something like the URP CopyDepth pass, where you need to add some extra MSAA resolve logic so your shader could use Tex2DMS samples based on whether the source texture is MSAA'd or not.

The SRP Blitter will be extended and improved to cover more use cases over time, but DrawMesh will always give you fulll flexibility and customization if needed.

TL;DR: Use SRP Blitter if what you need to do is available and implemented in that API, use the DrawMesh approach for any other cases, avoid cmd.Blit() 

Link:

Feedback - Documentation and/or a Unity blog post on how to Blit in URP -- and what every Blit function does - Unity Forumhttps://forum.unity.com/threads/documentation-and-or-a-unity-blog-post-on-how-to-blit-in-urp-and-what-every-blit-function-does.1211508/How to perform a full screen blit in Single Pass Instanced rendering in XR | Universal RP | 12.1.4https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@12.1/manual/renderer-features/how-to-fullscreen-blit-in-xr-spi.html?_ga=2.19647224.1381759709.1644198124-1935516838.1625024991

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值