Hi all,
I’m using a compute shader to generate some fancy effects and need access to the depth texture.
The part I’m stuck on though is how to get access to it in OnRenderImage().
I’m using the standard 3D project pipeline and targeting Windows stand alone. I’m rendering in deffered mode.
I have turned on depth mode for the camera using: m_Camera.depthTextureMode = DepthTextureMode.Depth;
I tried:
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Texture depth = Shader.GetGlobalTexture("_CameraDepthTexture");
if(depth != null)
{
m_RayMarchShader.SetTexture(0, "_DepthTexture", depth);
}
///more code here
But the texture that arrives in the shader is empty.
I tried blitting it straight to the screen and just get a black screen:
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Texture depth = Shader.GetGlobalTexture("_CameraDepthTexture");
Graphics.Blit(depth, destination);
}
I also tried other ways of getting the depth texture:
m_RayMarchShader.SetTextureFromGlobal(0, "_DepthTexture", "_CameraDepthTexture");
and
m_RayMarchShader.SetTexture(0, "_DepthTexture", source, 0, UnityEngine.Rendering.RenderTextureSubElement.Depth);
but got the same result.
Am I missing something? Is there a better way to get the depth texture for the current frame in OnRenderImage()?