Pulling my hair on this one, I have a render feature where I want to draw meshes in a custom order, so I’m running CommandBuffer.DrawRenderer(). Which works fine, but I cant set or change render targets. For example, adding this line in Execute():
does nothing, _depthLUT remains black and DrawRenderer works as normal, rendering to the screen. Any idea why this is happening? I’d like to render some stuff on a secondary texture.
Out of interest, do you know where it says this in the documentation? I’ve heard it said before on the forums but I can’t find the doc reference.
OP:
buffer.SetRenderTarget(int) and (RTHandle) work fine for me on 2019, 2020, 2021, and 2022, including the optional versions where depth is specified.
e.g.
buffer.SetRenderTarget(_OutlineObjectBuffer);
context.ExecuteCommandBuffer(buffer);
CommandBufferPool.Release(buffer);
// make sure you execute the buffer before using context.DrawRenderers
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings);
where _depthLUT remained black and it just rendered to the camera target.
However, when I tried:
ConfigureTarget(_depthLUT,);
It renders correctly to the _depthLUT target, without showing anything on the screen. So I’m not quite sure why this is happening. For info, this is what the frag shader that is used to render looks like:
We’ve probably read the same forum posts To which I’m clenching in absence of any concrete explanation. The C# function summary does say the same thing. I believe If ConfigureTarget isn’t used, URP assumes you’re targeting the current camera color target, which may have some adverse effect. I suppose it doesn’t hurt to be explicit.
In the same pass where I was looking, I actually also use CommandBuffer.SetRenderTarget in the Execute function, and that works perfectly.
The key may be to execute+clear the command buffer right after doing so for it to work (like you have as well).
Tried a multitude of combinations, it seems SetRenderTarget() works properly for a single color target, but when an array is given it always resets to the default single camera target, no matter what combinations. This seems like a bug.
I can report it also works when setting a color target and a depth target (both RenderTargetIdentifier or RTHandles). I have not used the array functionality before though.