参照了wiki:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Transparency
先上图:
下面是代码:
Shader "Custom/ShaderExample6"
{
Properties
{
}
SubShader
{
Tags { "Queue" = "Transparent"}
Pass
{
//第一个Pass渲染back face
Cull Front
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha //use alpha blending
GLSLPROGRAM
#ifdef VERTEX
//顶点着色器
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
//片元着色器
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.3); //半透明红色
}
#endif
ENDGLSL
}
Pass
{
Cull Back
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
GLSLPROGRAM
#ifdef VERTEX
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
gl_FragColor = vec4(0.0, 1.0, 0.0, 0.3); //半透明绿色
}
#endif
ENDGLSL
}
}
}