- Home /
Question by
chinadv · Jul 28, 2017 at 09:08 AM ·
renderingrendertexturepost-process-effectcommanddepth-buffer
commandbuffer can't get depth buffer in forward rendering but correct in Deferred .Why?
public void Awake()
{
MainCamera = GetComponent<Camera> ();
MainCameraRT = RenderTexture.GetTemporary (Screen.width, Screen.height, 24);
depthTexture = Texture2D.CreateExternalTexture (Screen.width, Screen.height, TextureFormat.RGB24, false, false, MainCameraRT.GetNativeDepthBufferPtr ());
cmdBuffer = new CommandBuffer();
cmdBuffer.name = "cmdBuffer";
cmdBuffer.SetRenderTarget(BuiltinRenderTextureType.CurrentActive);
cmdBuffer.ClearRenderTarget(false,true,Color.blue);
cmdBuffer.Blit (BuiltinRenderTextureType.CurrentActive, MainCameraRT);
MainCamera.AddCommandBuffer(CameraEvent.AfterSkybox, cmdBuffer);
}
qq截图20170728170128.png
(11.5 kB)
qqq.png
(5.7 kB)
Comment
Answer by $$anonymous$$ · Aug 12, 2020 at 07:18 PM
I would like to know the answer to this as well. I am begging to suspect that the answer is manually redraw the scene using a depth material.
Your answer
![](https://koobas.hobune.stream/wayback/20220612131355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get depth texture and render texture from one camera 0 Answers
Upsidedown depth buffer? (SRP/MRT) 0 Answers
Is there a way to write to Deferred Depth from a command buffer in CameraEvent.AfterImageEffects? 1 Answer
Camera depthbuffer question. 0 Answers
Modify values on VolumeProfile URP. 1 Answer