问题
I combined two shaders which can show transparency and cutoff Alpha. It works pretty fine, just two small problems stay. (1) in some specific camera angles the cutoff regions of an object are visible (only if a another object with the same shader is located behind that one) (2) if I fade out an object it's getting black not transparent
I'm new to shader-coding, thanks a lot for your help!!
Here's the shader:
Shader "Unlit/MyTransparent"
{
Properties{
_Color("Main Color", Color) = (1,1,1,0.5)
_MainTex("Base (RGB) Alpha (A)", 2D) = "white" {}
_Cutoff("Base Alpha cutoff", Range(0,0.9)) = 0.5
}
Category{
//Tags{ "QUEUE" = "AlphaTested" "IGNOREPROJECTOR" = "true" "RenderType" = "Transparent" } // Transparent beides
Blend SrcAlpha OneMinusSrcAlpha
SubShader{
Material{
Diffuse[_Color]
Ambient[_Color]
}
Pass{
AlphaTest Greater[_Cutoff]
SetTexture[_MainTex]{
combine texture * primary, texture
}
}
Pass{
GLSLPROGRAM
varying mediump vec2 uv;
uniform mediump vec4 _MainTex_ST;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
}
uniform lowp sampler2D _MainTex;
uniform lowp vec4 _Color;
void main() {
gl_FragColor = texture2D(_MainTex, uv) * _Color;
float ca = tex2D(_CutTex, IN.uv_MainTex).a;
}
ENDGLSL
}
Pass{
ZWrite Off
SetTexture[_MainTex]{
//combine texture * primary, texture
Combine texture * constant ConstantColor[_Color]
}
}
}
SubShader{ Pass{
SetTexture[_MainTex]{ Combine texture * constant ConstantColor[_Color]}
} }
}
}
来源:https://stackoverflow.com/questions/39677847/unity-gameobjects-invisible