The only overloads of CommandBuffer.SetRenderTarget that allow for MRT (multiple targets) also require a depth buffer to be specified. For example, SetRenderTarget(RenderTargetIdentifier[ ] colors, RenderTargetIdentifier depth).
What is the proper value to pass for depth when there is no depth buffer?
I’m working on the builtin render pipeline, on 2021.3.1.
I’ve tried the obvious things, like (RenderTargetIdentifier)RenderTargetIdentifier.AllDepthSlices, but without success. In fact, this appears to lead to buggy behaviour. As confirmed by RenderDoc, this sometimes does what I’m wanting, and sometimes errors with Invalid output merger - Depth target is different size or MS count to render target(s). The behaviour appears 50/50 random between frames.
Note that that’s an error showing up in RenderDoc. Unity itself doesn’t display any error, it simply fails to switch render targets, and clears the previously bound one instead.
My comlete test repro, there’s nothing else in this project interfering here.
var cb = new CommandBuffer();
var textureId = Shader.PropertyToID("RenderTextureName");
cb.GetTemporaryRT(textureId, new RenderTextureDescriptor(
width: 1024,
height: 1024,
colorFormat: RenderTextureFormat.ARGB32,
depthBufferBits: 0,
mipCount: 0
));
// This works fine
//cb.SetRenderTarget(textureId);
// This breaks
//cb.SetRenderTarget(textureId, (RenderTargetIdentifier)RenderTargetIdentifier.AllDepthSlices);
// As does this, which is what I'm actually trying to do
cb.SetRenderTarget(
new RenderTargetIdentifier[] {
textureId,
/*and others*/
},
(RenderTargetIdentifier)RenderTargetIdentifier.AllDepthSlices
);
cb.ClearRenderTarget(false, true, Color.blue);
Graphics.ExecuteCommandBuffer(cb);
I’m hoping this is a me problem, and not another case of finding an engine bug within an hour of trying to do some interesting rendering work.
