I am working on a skin shader which needs to be able to handle transparency but at the same time not have the usual depth buffer issues that the builtin transparent shaders have. I have added an extra pass to solve this. At the moment I am using a Queue tag of “Transparent-1”, which handles very well in relation to other transparent objects that are behind and infront. However the problem comes when I try to make the material completely transparent, since it creates a hole or void in its place:
I’ve found I can solve this by simply changing the Queue tag to “Transparent”. This gets rid of the void when completely transparent, but instead creates some z-fighting issues with other transparent objects. Notice the 6 figures in the red cube volume (please excuse their strange test outfits):
If we look at the red volume from an ortho top view you’ll notice that all the 6 figures are clearly inside it, yet in the above screenshot the z-fighting is making them appear as outside of it.
Any suggestions on how I should fix this, is there a particular property that would be helpful in my case? I’ve been playing around with this shader for quite some time now and I can’t come up with anything.
Here is my shader code:
Shader "Player/Human Skin" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_AlphaMap ("Transparency", 2D) = "white" {}
_BumpMap ("First Normal Map", 2D) = "bump" {}
// Slider to control fading between normalmaps
_BumpMapSlider ("Normal Slider", Range (0, 1)) = 0
// Second normal map
_BumpMap2 ("Second Normal Map", 2D) = "bump" {}
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="False" "RenderType"="Transparent" }
LOD 400
//For getting rid of Z-fighting
Pass {
//ZWrite On
ColorMask A
}
CGPROGRAM
#pragma surface surf BlinnPhong alpha
#pragma exclude_renderers flash
sampler2D _MainTex;
sampler2D _AlphaMap;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;
// Remember to add your properties in here also. Check ShaderLab References from manual for more info
float _BumpMapSlider;
sampler2D _BumpMap2;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Gloss = c.a;
o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r;
o.Specular = _Shininess;
// Read values from _BumpMap and _BumpMap2
fixed3 normal1 = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
fixed3 normal2 = UnpackNormal(tex2D(_BumpMap2, IN.uv_BumpMap));
// Interpolater between them and set the result to the o.Normal
o.Normal = lerp(normal1, normal2, _BumpMapSlider);
}
ENDCG
}
FallBack "Transparent/Bumped Diffuse"
FallBack "Transparent/VertexLit"
}
The reason I use the extra pass. Without it the inner parts (mouth, teeth etc) of my character are visible through their head. Notice the big black poke through: