[Unity 2020.3 in URP]
I have been working on blending cameras with different culling masks. I got it working exactly how I wanted, but it stopped working without any changes to the code. I had working versions on the previous git commits, but once I reverted to the commits, it was no longer working.
I was using RenderTexture.active and Graphics.Blit() to overlay one camera render texture over another (Note that this is set up for VR using depth layers and WAS working in Multipass and SinglePass):
// All fields are created in script.
public Camera blendLayerCamera;
public Camera mainCamera;
public RenderTexture leftRenderTexture;
public RenderTexture rightRenderTexture;
// Subscription: RenderPipelineManager.endCameraRendering += RenderPipelineManager_endCameraRendering
private void RenderPipelineManager_endCameraRendering(ScriptableRenderContext context, Camera camera) {
if (camera == blendLayerCamera)
{
RenderTexture active = RenderTexture.active;
Graphics.Blit(
source: active,
dest: leftRenderTexture,
sourceDepthSlice: 0,
destDepthSlice: 0);
Graphics.Blit(
source: active,
dest: rightRenderTexture,
sourceDepthSlice: 1,
destDepthSlice: 0);
}
else if (camera == mainCamera)
{
Graphics.Blit(leftRenderTexture,
RenderTexture.active,
leftBlendMat, -1, 0);
Graphics.Blit(rightRenderTexture,
RenderTexture.active,
rightBlendMat, -1, 1);
}
}
The problem is RenderTexture.active was originally set to the camera’s render, but it is now (and in the commits) RenderTexture.active is null.
I’m not sure if something is not being tracked in the project settings, or if this setup is not reliable. Anyone with any insights would be helpful