I have a very simple goal, apply a mask on a rendertexture after that display it on a GUI.
i use the following code, it works perfectly on windows platform, but on mac platform the mask has no effect at all. the entire rendertexture was showing on the GUI.
Shader "Hidden/Mask Off" {
Properties {
_MainTex ("Base (RGB)", RECT) = "white" {}
_MaskTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform samplerRECT _MainTex;
uniform sampler2D _MaskTex;
float4 frag (v2f_img i) : COLOR
{
float4 rt = texRECT(_MainTex, i.uv);
float4 mask = tex2D(_MaskTex, i.uv);
rt.a = 1;
return min(rt, mask);
}
ENDCG
}
}
Fallback off
}
_MainTex is the rendertexture and _MaskTex is the mask texture (ARGB), and the technique is very simple,
- set the rendertexture alpha to 1 (ignore the rendertexure alpha channel)
- get the min value of the rendertexture and mask. on wanted area the mask’s color is white and alpha is 255, on unwanted area the mask’s color is black and alpha is 0, therefore min() could be used to mask out the unwanted area.
Help please.