Hi,
I implemented a rendering pipeline in Unity and it worked well on Windows DirectX11, Windows OpenGL and PS4 until my upgrading from Unity 5.4.2p to Unity 2017.1.0p. Now it works on Windows OpenGL but fails the same way on Windows DirectX11 and PS4.
To make it clear and short and to narrow the problem, I will list the conclusion from the test:
- The problem seems related to the code segement:
Graphics.SetRenderTarget(colorBuffers, depthBuffer);
material.SetMatrix(“_WVP_Matrix”, matrix);
material.SetPass(0);
Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
-
I had drawn some meshes (depth) into the depthBuffer before I set it as the render target. However, the mesh drawn by Graphics.DrawMeshNow was not affected by those depth (Z test did not work)
-
However, the depthBuffer was not cleared and Z-Test was enabled. Z-Test could be actually done correctly between the meshes Graphics.DrawMeshNow drew and wrote the depth back into the depthBuffer.But the depth that was wrote back seems always smaller than the depth that was output by other draw calls (with Camera.Render).
-
Another thing I think needs to be mentioned : Graphics.DrawMeshNow uses left handed coordinate system on Windows DX and PS4 rather than the right handed system on Windows OpenGL. So I use different world view projection matrix on different platforms for Graphics.DrawMeshNow. Although it worked fine with Unity 5.4.2p, I wonder if the problem has something to do with it.
-
With all the points above, my guess would be : Everything worked as expected, except the depth that was output by Graphics.DrawMeshNow somehow is mapping into a small range, say [0, 0.1], instead of [0, 1.0], which I am not sure if there is a way to do that.
So if anyone have a clue, I need your help, thanks!