I’m trying to write shader that gets color from RGB texture and Alpha8 texture for alpha.
Shader looks like this:
Shader "SeparateAlphaOpacity" {//
Properties {
_MainTex ("Diffuse", 2D) = "white" {}
_AlphaTest("AlphaMap",2D) = "white" {}
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Lighting Off
ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
//float4 _MainTex_ST;
sampler2D _AlphaTest;
//float4 _ShadowTex_ST;
struct vertexInput {
half4 vertex : POSITION;
fixed2 texcoord : TEXCOORD0;
};
struct vertexOutput {
half4 pos : SV_POSITION;
fixed2 tex : TEXCOORD0;
};
vertexOutput vert (vertexInput v)
{
vertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.tex = v.texcoord;
return o;
}
half4 frag (vertexOutput i) : COLOR
{
half4 tex = tex2D(_MainTex, i.tex.xy); //,i.tex.xy * _MainTex_ST.xy + _MainTex_ST.zw);
half4 alphaMap = tex2D(_AlphaTest, i.tex.xy);//,i.tex.xy * _ShadowTex_ST.xy + _ShadowTex_ST.zw);
return half4(tex[0],tex[1],tex[2],alphaMap[3]);
}
ENDCG
}
}
}
Shader works on mobile platforms and on OSX, but doesn’t work on Windows.
It works also on windows if I return for example this half4(1,tex[1],tex[2],alphaMap[3]); Ofcourse one color is missing in this case. But whenever I plug all 4 colors into it, stops working.
There is no error, just it renders like whole alpha is value 1. (pure RGB image without transparency)
Any ideas about this strange issue?