Search Unity

Why is Z cleared after Depthpass

Discussion in 'General Graphics' started by Sh-Shahrabi, Mar 25, 2019.

  1. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    I am looking in to a VR scene where a depth pass is rendered first before the main render using the shadow caster pass of the materials. The mesh are unlit, however for post process, the Camera depth texture is required. (Why the post process can't just use the Z buffer after the main render, I don't understand, but that is a different topic). My first assumption was that at the very least Unity would use the shadow pass which is typically used for shadow mapping, as an early Z test to avoid over draws on Opeque geometry that occlude themselves. But that is not the case, the Z buffer is cleared after the pre pass. Why is that?
    I tested this on multi pass VR, single stereo and single instanced. In all the cases the Overdraw is the same (I test this using an opaque shader with One One additive blending) and the frame debugger shows the Z is always cleared after the pre pass.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The depth texture pass does not use MSAA, where as the main camera rendering may. You can't mix the depth buffers from a non-MSAA and MSAA render target. And while you could inject the non MSAA depth into the MSAA target with a blit, it would defeat the point of having MSAA enabled in the first place.
     
    Sh-Shahrabi likes this.
  3. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    That makes sense. Thank you.