I still have a problem with this though, as i need the ZWrite to not be Off to get the correct result for upper and under sides of water at same time, so i wonder if this is a known bug in Mac and Metal.
Hi, we are facing similar issue with water. When reading data from _CameraDepthTexture and ZWrite On we are getting nasty artifacts.
I have tried various approaches to get copy of DepthBuffer, but with no result. When sampling _CameraDepthTexture directly artifacts are there, from that _CameraDepthTexture should cause the problems.
metal needs you to create a custom copy of the depth buffer when it comes to deferred – which can then be used by the water to do depth related calculations.
see lux water
This is probably not so straightforward as it looks. We would like to obtain that texture between some opaque draw calls. But only place where it is possible to copy it is AfterDepthTexture, which is way behind what we need
Do you know why it is not supported? Seems a little buggy to me that Grab texture works, so the copy of color buffer is ok, but the copy of depth buffer is not ok? It is almost the same resource produced while rendering. In fact, on the deferred renderer it should be much harder to obtain copy of the color buffer, than the copy of depth buffer i guess.
Yes, that correct question. I haven’t time to test it, but Before/AfterForwardOpaque should be just fine even on the deferred rendering path? From my point of view, color buffer and depth buffer should be accesible here to make a copy. Am i right?
i tried do the fill of depth buffer in a million ways and none seems to work out correctly, i still get either black artifacts or overlapping polygons or polygon gaps in my water mesh
After many investigations, you will find that Metal probably passes to _CameraDepthTexture, current depth buffer. From my point of view, due to synchronization it is impossible to read and write to that texture. If you need this functionality on metal best for you will be do a copy beforehand and then pass it to your shader as _CameraDepthTextureCopy for example and don’t access _CameraDepthTexture at all. Or you can use _CameraDepthTexture, but then you will have turn off ZWrite and somehow tackle issues connected to that
You can copy _CameraDepthTexture using Blit into arbitrary texture