- Home /
Reverse Z-Buffer Effect
I'm trying to achieve a reversed Z-buffer for an effect where farther objects render on top of closer ones. But I can't seem to find any straight-forward way to do it. What I've tried so far:
Use ZTest GEqual
In order to use this, I have to clear the depth-buffer with the minimum value instead of the maximum value first, but I can't find any simple way to do that through Unity.
Change the clip range
This would be my ideal solution, to use something like glClipControl to use the -1 to 1 range instead of 0 to 1. Then I could just make the w component negative and get the desired effect. But it doesn't seem like Unity supports this, and it's a relatively new feature so I'm not sure if it will be very compatible on different platforms.
Directly set the depth using SV_Depth in the fragment shader
It works, but not with MSAA, it creates seams. I'm pretty sure that the vertex coordinates are being interpolated, and in the case of MSAA sometimes extrapolated, and this causes the wrong depth to be written to some places. At least, that's my theory, maybe there's something else going on here, not sure.
Any help to point me in the right direction would be appreciated!
Hey @Kevin_H_ , In Depth Precision the guy write about that issue at hand. I'm afraid I still didn't check how he implemented it, but let's try together to do that :)
Your answer
Follow this Question
Related Questions
ZTest, and ZWrite Problem rendering a Cluster of Quads 2 Answers
ZTest Always for standard shader is not working? 0 Answers
ZTesting on certain steamVR games causes right eye to not display material correctly 0 Answers
Display complex object when it is behind the wall 5 Answers
How to force the compilation of a shader in Unity? 5 Answers