I created a material using the following shader, put that material on a cube in a scene.While in Editor, shader_feature(both on & off) is working correctly.
But when I build it to mobile(android), the shader_feature code are always turned off.
if I switch shader_feature to multi_compile instead, it works in mobile.
if I copy the whole pass’s code and use it to replace the UsePass"" line, it works in mobile.
Shader "UsePassWithShaderFeature"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[Toggle(INVERT_ON)]_invert("invert?",float) = 0
}
SubShader
{
//UsePass will lose all shader_feature code when build
UsePass "Hidden/PassWithShaderFeature/COLOR"
}
}
Shader "Hidden/PassWithShaderFeature"
{
SubShader
{
//We only need the Pass itself
Pass
{
Name "COLOR"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature _ INVERT_ON
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
#if INVERT_ON
col = 1 - col;
#endif
return col;
}
ENDCG
}
}
}
so question is:
can I use UsePass while the pass contains shader_feature?
if not, any better workaround?
(can not replace shader_feature with multi_compile, as there are lots of variants - 2^n)
(can not copy the pass as it makes maintenance very difficult)
using Unity5.5.0f3