Graphics.Blit does not copy RenderTexture depth


  • I have two RenderTextures with format RenderTexture.Depth, Graphics.Blit is not copying the depth values from one to the other.


Graphics.Blit draws a quad with Z-Write off, so the depth will not be copied from one RenderTexture to another.


Create a "DepthBlit" Shader to sample and output the Depth Texture as depth values:

// Fragment function outputs depth from _MyDepthTex to depth buffer
half4 CopyDepthBufferFragmentShader(v2f i, out float outDepth : SV_Depth) : SV_Target
float depth = SAMPLE_DEPTH_TEXTURE(_MyDepthTex, i.uv);
outDepth = depth;
return 0;

The complete Shader is also in this article as an attachment. Note: the GPU needs to support GL_FragDepth extension in order to output the depth, most GPUs do, but some older mobiles might not.

Then in C# create a Material and do the Blit using it:

// Create a Material that uses the DepthCopy Shader
Material m_DepthCopyMat = new Material(m_DepthCopyShader);

// Set the _MyDepthTex Shader Texture to our source depth texture to be copied
m_DepthCopyMat.SetTexture("_MyDepthTex", m_SrcDepthTexture);

// Do a Blit using the DepthCopy Material/Shader
Graphics.Blit(m_SrcDepthTexture, m_DstDepthTexture, m_DepthCopyMat); 

More Information:

If you do not want to copy the Depth Texture but instead want to have a valid depth buffer that can be shared between the Render Targets then you can use:

Graphics.SetRenderTarget(rendertexture.colorBuffer, depthRT.depthBuffer);

before rendering a fullscreen quad for your blit.

Manual page on how to use depth textures in Unity:

Information verified accurate for Unity 5.4.3p4.

Was this article helpful?
4 out of 6 found this helpful
Have more questions? Submit a request


  • 2
    Lee Wood

    This doesn't work in the non-CG pipelines (that unity recommends) and no other solutions are easily found. The complete lack of support fixing issues that are broken in unity's recommended solutions is disheartening. I'm not certain I would have chosen unity had I known the engine often doesn't work.

Please sign in to leave a comment.