How can I manage the ZDepth for a fade object- Shader Unity

Hi guys,

I try to cut a fade Object in my scene. This Fade object has a Standard Shader with “pragma alpha” to change his opacity value at runtime with C#.

The problem of the “alpha” property is the object has some artefacts on it

So I use the ZWrite On option in a Pass to fixe it.

But now I have a problem with this ZBuffer because it hides me part of my object like :


Someone has an idea ? Maybe a Unity developer can help me because nobody speaking about that and I checking a solution since few days.


In the first picture it looks like there are 2 meshes on top of each other, is that the case? Does the shader have multiple passes? Would you mind posting your shader?

You can always debug your ZBuffer by messing around with ZTest: Unity - Manual: ShaderLab: commands


I use my shader to dynamically managing object’s opactiy at runtime and to cut my objects when they intersect a plane.
To do that, I’m discarding the pixel when his distance to the plane is < 0.

But I forgot to do the same in the Pass managing the ZDepth.

My error was here. Just need to add the same condition to discard pixel color in depth Pass.