Command Buffer and ZTest

I Use Command Buffer and “DrawRenderer” to add a couple of additional renderers with a custom material to camera render sequence, but it seems that my shader settings for ZTest are ignored. The objects seem to be drawn in the order in which they were added to the command buffer regardless of their depth. I shove the command buffer in “CameraEvent.BeforeImageEffectsOpaque”.

The strange thing is, that if i add the Optimized blur from Unity standard assets to the camera that results in everything getting drawn with proper depth test.

So in general is the injection area wrong, does command buffer simply forgo depth test or is there something I fundamentally don’t get about computer graphics render sequences/tests etc.?

Thank you for your time! :slight_smile:

EDIT #1

So I’ve been trying to narrow down what causes the proper depth test in optimized blur. And it seems that simply adding this to the camera that has the command buffer assigned, makes the content of the command buffer adhere to depth:

void OnRenderImage (RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination);
}

As to why I cannot say yet. Since my command buffer has around ~4 renderers, and this “OnRenderImage” doesn’t get called more than once per frame, it seems that it simply copies a complete texture into another complete texture. Why this copying forces the command buffer commnads to adhere to depth, I do not know.

EDIT #2

Solved, problem was a simple mistype.

1 Like

I’m having a similar problem. Could you please elaborate on the mistype?

In case anyone still comes across this issue, I had the same and in my case it was also a simple mistake that was probably the same as the one in the original post.

When getting the temporary render texture in the command buffer, I mistakenly gave the depth buffer a bit size of 0 instead of 16 or more. It looked something like this:

_commandBuffer.GetTemporaryRT(_prePassRenderTexID, Screen.width, Screen.height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, QualitySettings.antiAliasing);

It should have looked like this:

_commandBuffer.GetTemporaryRT(_prePassRenderTexID, Screen.width, Screen.height, 16, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, QualitySettings.antiAliasing);

1 Like

It was still not worded…
I had checked the depth info in Frame Debugger, it just a pure white picture when executed “commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, [RT with depth], [material with Z Write on]);” .

Its GlowingObjectOutline case.I have the same issue.but channge 0 to 16.not Work.The problem is still here!!

I have same issue .How can you solved it??

Do you find the answer??

As Edit #2 states it’s my own mistake. As far as I remember, I also gave the depth buffer 0 size when creating the texture.

I find the answer in below link
https://www.wonderm.cc/2019/03/04/CommandBuffer-01/

Incredible
6733948--775384--upload_2021-1-17_16-55-54.png

1 Like