Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Camera.SetTargetBuffers problem?

Discussion in 'Shaders' started by SpookyCat, Jan 22, 2020.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,746
    I am trying to get a simple two camera setup working so I can use the depth buffer from the second camera with the color buffers from both. My combining shader uses the _LastCameraDepthTexture value but that always seems to point at the first camera. I was rendering my second camera to a render texture which works but I again I cant access the depth buffer for that in my combining shader. I then created a color rendertexture and a depth rendertexture and used the Camera.SetTargetBuffers to assign them to the second camera. But when I try and use those textures in my combine shader they seem to be empty. The second camera still seems to draw to the screen, is that expected after target buffers have been assigned?
    Am I missing something to get this to work? I was hoping that just setting a RenderTexture to the second camera and have that being drawn second would mean the _LastCameraDepthTexture would be the depth texture for that camera but it is always the first cameras buffer.