我合并了两个可以显示透明度和截止Alpha的着色器。它工作得很好,只留下两个小问题。 (1)在某些特定的摄像机角度中,对象的截止区域是可见的(仅当具有相同着色器的另一个对象位于该对象后面时) (2)如果我淡出一个物体,它会变黑而不透明
我是shader-coding的新手,非常感谢你的帮助!!
这是着色器:
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]}
} }
}
}