- Home /
Shader alpha depth problem?
I have this shader for a mobile game:
Shader "Unlit/Transparent" {
Properties {
_Color ("Main Color (A=Opacity)", Color) = (1,1,1,1)
_MainTex ("Base (A=Opacity)", 2D) = ""
}
Category {
Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
SubShader {Pass {
GLSLPROGRAM
varying mediump vec2 uv;
#ifdef VERTEX
uniform mediump vec4 _MainTex_ST;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
}
#endif
#ifdef FRAGMENT
uniform lowp sampler2D _MainTex;
uniform lowp vec4 _Color;
void main() {
gl_FragColor = texture2D(_MainTex, uv) * _Color;
}
#endif
ENDGLSL
}}
SubShader {Pass {
SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]}
}}
}
}
My problem is, that I want it like image 3. Now it looks like image 2 :
How can I do it like image 3? The shader alpha must be changeable.
u-1.png
(36.8 kB)
Comment
Best Answer
Answer by helarts · Dec 05, 2015 at 03:31 PM
You can try with the Stencil Buffer, add this line 12, it seems to work:
Stencil {
Ref 1
Comp Greater
Pass IncrSat
}
Note that Stencil buffer is used to compute lighting on opaque objects in deferred rendering, so you may want to clear the buffer with Camera.clearStencilAfterLightingPass if you are not using Forward Rendering Path.
More about Stencil Buffer: http://docs.unity3d.com/Manual/SL-Stencil.html
screenshot-2015-12-05-16-17-41.jpg
(8.2 kB)