Question by
vanshika1012 · Jan 06, 2017 at 05:42 PM ·
shader programmingshaderlabcgshader writing
Mask Shader Problem in Unity
I am trying to use Mask Shader. Strangely this shader working fine on Unity3d Editor and Android, but not working on iOS. It gives me weird result and after iOS build it stops working on Editor as well. Below is the code of my Shader. I guess, there must be some logical reason. I am not "PRO" at shader writing. Hope someone help.
Below shader, basically unMask the image on touch. This Mask Shader is applied on top layer and when I touch it, it shows me below image. Just like scratch effect.
Shader "Masked" {
Properties {
_MainTex ("Main", 2D) = "white" {}
_MaskTex ("Mask", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
ZTest Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform sampler2D _MaskTex;
uniform float4 _MainTex_ST;
uniform float4 _MaskTex_ST;
struct app2vert
{
float4 position: POSITION;
float2 texcoord: TEXCOORD0;
};
struct vert2frag
{
float4 position: POSITION;
float2 texcoord: TEXCOORD0;
};
vert2frag vert(app2vert input)
{
vert2frag output;
output.position = mul(UNITY_MATRIX_MVP, input.position);
output.texcoord = TRANSFORM_TEX(input.texcoord, _MainTex);
return output;
}
fixed4 frag(vert2frag input) : COLOR
{
fixed4 main_color = tex2D(_MainTex, input.texcoord);
fixed4 mask_color = tex2D(_MaskTex, input.texcoord);
return fixed4(main_color.r, main_color.g, main_color.b, main_color.a * (1.0f - mask_color.a));
}
ENDCG
}
}
}
Comment