- Home /
ZWrite only for the object itself
Can i enable ZWrite only for the object itself, so when it's half transparent only the front part is rendered, but have it disabled for others, so that the object appears through them ?I have this shader right now :
Shader "Transparent/Diffuse ZWrite" {
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
LOD 200
// extra pass that renders to depth buffer only
Pass{
ZWrite Off
ColorMask 0
}
// paste in forward rendering passes from Transparent/Diffuse
UsePass "Transparent/Diffuse/FORWARD"
}
Fallback "Transparent/VertexLit"
}
If i set ZWrite Off
transparency works, but i can see the faces whose normals face me, but are behind the visible part of the mesh. And when i set ZWrite On
the mentioned faces are no longer visible, but nor are those hidden behind ANOTHER object in front of the original, whose transparency is set to 0.
Torus with Standard Material: With Diffuse ZWrite Material, ZWrite Off: With Diffuse ZWrite Material, ZWrite On (With a cube with the same material,completely transparent and partly covering the torus) The obvious solution for two objects is to make two shaders, one with ZWrite on, and the other off, and that's what i'm trying to do right now, but it involves first alot of coding, and second changing shaders constantly, and i don't know if the last's healthy in terms of performance. Any ideas ? Thanks for reading !