- Home /
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.
Thanks
Answer by Thibault_Lesaunier · Apr 16, 2018 at 12:46 PM
Hi,
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.
Good to hear that you fixed it. I believe, if you are discarding pixels, you might aswell use alpha cutoff since regular transparency will bring sorting issue.
Answer by callebo_FK · Apr 16, 2018 at 12:07 PM
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: https://docs.unity3d.com/Manual/SL-CullAndDepth.html