- Home /
Duplicate Question
Mask shader on Android devices
Hi,
I'm currently working on a 2D game. For some feedback purpose I want to use a mask on a quad in order to make some parts of the quad transparents. To achieve this I use two shaders (one for the quad in background, and one on another quad to use it as mask). Here they are:
The shader used on the background quad
Shader "FeedbackBG" {
Properties {
_MainTex("Base (RGB)", 2D) = "" {}
}
SubShader {
Tags {"Queue" = "Geometry+10"}
Pass {
Cull Off
Lighting Off
ZWrite On
ZTest LEqual
SetTexture [_MainTex] {}
}
}
Fallback "Diffuse"
}
The one used on the mask
Shader "TexturedMask" {
Properties {
_Mask ("Culling Mask", 2D) = "white" {}
}
SubShader {
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
Tags {"Queue" = "Geometry+10"}
Tags { "Queue" = "Transparent" }
ColorMask 0
ZWrite On
ZTest Always
Alphatest LEqual 0.5
Pass {
SetTexture[_Mask] {}
}
}
}
The combination of both works perfectly when I test it thanks to the webplayer but on Android devices (Samsung Galaxy S2 and Nexus7) only the background is displayed and the mask is not applied. As I'm not really good in making shaders I wonder what I missed?
Any help would be appreciated. Thank you.
don't know much about shader code.. but generally multiple shaders, transparency and particularly using a culling mask are costly to the gpu, and can cause many issues with different mobile devices (Though I believe I have used a similar setup successfully with my Galaxy S2... but the same build caused issues on other devices anyway..)
for maximum compatibility, at least avoid the AlphaTest part.. this "clip instruction" will DEFINITELY cause issues on some devices
Answer by lvictorino · Dec 26, 2012 at 10:19 AM
I've finally put another camera to produce the mask effect. As explained here : http://answers.unity3d.com/questions/56564/treating-an-animated-sprite-as-a-mask.html