In our project, we copy the content of depth buffer generated by depth pass, to the depth buffer used by rendering opaque objects, trying to utilize Early Z to avoid some cost of executing pixel shader. Everything is OK except some meshes which using dynamic batching are not rendered correctly. Using RenderDoc, I found the depth value generated by two passes (depth pass and drawing pass) of these objects are not the same completely. (Object maybe rendered as a single mesh in depth pass, and rendered using dynamic batching in drawing pass) I test in 5.4.0f3. The project can be downloaded in this link. To reproduce: Play the scene "test.unity" Use WASD to move camera, you can see the most left tree is not rendered correctly. (On my machine, I move camera right a little, then move camera up) I have two questions: Is this an expected behaviour or a bug? Why are some objects rendered as a single mesh in depth pass while it can use dynamic batching obviously? (I think if all objects are consistent with dynamic batching in depth pass and drawing pass, this issue can be solved)
I posted a thread in beta forum, which needs HTC Vive to reproduce. But the above project can reproduce this issue without VR devices.
This sounds like the expected behavior. An object must use the same rendering choice in both passes (dynamic batching or single draw call) in order to work correctly. Otherwise, small mathematical differences will appear due to floating point precision.
Hey @Alan-Liu, Regarding your second question, it's not always the same batching criteria in depth pass and shading pass, as the material states and shaders (pass) used are different.