【URP】In the render graph API, the output Render Texture must have a depth buffer.

起きた事象

unity6のURPへアップデートした直後、以下の警告が出るようになった。

In the render graph API, the output Render Texture must have a depth buffer. When you select a Render Texture in any camera's Output Texture property, the Depth Stencil Format property of the texture must be set to a value other than None.
UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset,intptr,UnityEngine.Object,Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle)

環境

unity6.0(6000.0.63f1) URP17.0.4

対処法

レンダラーテクスチャの深度バッファのbit数を0に指定している箇所があるはず。

コードからだとこういうもの。

RenderTexture tex = new RenderTexture(textureSize.w, textureSize.h, 0);
RenderTexture tex2 = RenderTexture.GetTemporary(textureSize.w, textureSize.h, 0); //Temporary使ってるならこんな感じ


深度バッファのbit数を指定する。
深度バッファのbit数は16,24,32のいずれかで指定する*1今迄0で問題なかったものは16が良いと思う。
(深度バッファに使われるメモリ使用量が一番小さいから)

RenderTexture tex = new RenderTexture(textureSize.w, textureSize.h, 16);
RenderTexture tex2 = RenderTexture.GetTemporary(textureSize.w, textureSize.h, 16); //Temporary使ってるならこんな感じ

なぜ?

これまで深度バッファを使わないレンダラーテクスチャでは、0を指定する方がメモリ使用量の削減になると考えていた。
しかし、Unity 6 のURPでは「Render Graph」*2という新しいレンダリングシステムに完全移行したらしく、
このシステムでは深度バッファが必ず使われる設計になっているため深度バッファのbit数の指定が必須となった。

これだけ見ると、メモリ使用量が増えてよくないように見えるが、それ以上のメリットがRender Graphにはあるらしい。→TODO

RenderGraphは無効にもできる。

都合が悪い人はProject Settingsの以下をチェックすると無効にすることもできる。

Graphics → Pipeline Specific Settings → URPタブ → Render Graph → Compatibility Mode (Render Graph Disabled)