- Home /
UI shader write to depth buffer
Hi everyone,
I have a few world space canvases which I'd like to have blurred by the post processing depth of field effect (from the post processing stack) like any other geometry. However since the default UI material does not write to the depth buffer I get some weird results. Therefore I downloaded the built-in shader made a copy of the ui-default shader and changed it's RenderType to TransparentCutout and ZWrite to on as suggested here: http://answers.unity3d.com/questions/582064/enable-sprite-depth-write.html
but that did not work. Any suggestions on what I am missing?
Answer by fleity · Jan 14, 2020 at 01:46 AM
okay it's two and a half years since this question. nevertheless I opened up a new unity project and set out to solve the same problem again.
Obviously to use any new shader it needs to be selected in material, that goes without saying, it is the only way. Replacement shader might be a way to solve it because on could render the object again with a shader that writes depth but is then overwritten again by the transparent rendering before we get to the post processing stage when the image is blurred.
However the closest to an actual answer to my question can probably be found in this thread, although a quick five minute copy paste of that code + adding a clip(alpha - 0.001) did not result in what I needed. With clip function nothing is written to depth, without the entire quad writes to depth.
The easiest and most sane way is to get a standard shader, set it to cutout and that just works. Somewhere in the standard shader is the solution for the UI-Cutout-DepthWrite shader but just using the standard shader is probably the right way to go about this.
Answer by JonPQ · Jan 13, 2020 at 08:54 PM
you'd need to put that shader on a material, and put that material on your ui or use camera replacement shader to render your ui objects with that shader