Search Unity

Command Buffer and ZTest

Discussion in 'General Graphics' started by Justinas_Ma, Jan 9, 2017.

  1. Justinas_Ma

    Justinas_Ma

    Joined:
    May 8, 2014
    Posts:
    31
    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! :)

    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.
     
    Last edited: Jan 10, 2017
    unity_9LD3cg9-iUFwGQ likes this.
  2. Benjamin_Overgaard

    Benjamin_Overgaard

    Joined:
    Jul 20, 2015
    Posts:
    17
    I'm having a similar problem. Could you please elaborate on the mistype?
     
  3. talila

    talila

    Joined:
    Mar 6, 2015
    Posts:
    26
    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);
     
    Justinas_Ma likes this.
  4. jacketjlz

    jacketjlz

    Joined:
    Apr 12, 2018
    Posts:
    1
    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]);" .
     
  5. Dr-Game

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161

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

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161
    I have same issue .How can you solved it??
     
  7. Dr-Game

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161
    Do you find the answer??
     
  8. Justinas_Ma

    Justinas_Ma

    Joined:
    May 8, 2014
    Posts:
    31
    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.
     
  9. Dr-Game

    Dr-Game

    Joined:
    Mar 12, 2015
    Posts:
    161
  10. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    156
    mpeddicord likes this.