1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

[bug/user's fault?] shader_feature will not include in build if used UsePass

Discussion in 'Shaders' started by colin299, Mar 17, 2017.

  1. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    100
    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.

    Code (CSharp):
    1. Shader "UsePassWithShaderFeature"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         [Toggle(INVERT_ON)]_invert("invert?",float) = 0
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         //UsePass will lose all shader_feature code when build
    12.         UsePass "Hidden/PassWithShaderFeature/COLOR"
    13.     }
    14. }
    15.  
    Code (CSharp):
    1. Shader "Hidden/PassWithShaderFeature"
    2. {
    3.     SubShader
    4.     {
    5.         //We only need the Pass itself
    6.         Pass
    7.         {
    8.             Name "COLOR"
    9.             CGPROGRAM
    10.             #pragma vertex vert
    11.             #pragma fragment frag
    12.  
    13.             #pragma shader_feature _ INVERT_ON
    14.             #include "UnityCG.cginc"
    15.  
    16.             struct appdata
    17.             {
    18.                 float4 vertex : POSITION;
    19.                 float2 uv : TEXCOORD0;
    20.             };
    21.  
    22.             struct v2f
    23.             {
    24.                 float2 uv : TEXCOORD0;
    25.                 float4 vertex : SV_POSITION;
    26.             };
    27.  
    28.             sampler2D _MainTex;
    29.             float4 _MainTex_ST;
    30.          
    31.             v2f vert (appdata v)
    32.             {
    33.                 v2f o;
    34.                 o.vertex = UnityObjectToClipPos(v.vertex);
    35.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    36.                 return o;
    37.             }
    38.          
    39.             fixed4 frag (v2f i) : SV_Target
    40.             {
    41.                 // sample the texture
    42.                 fixed4 col = tex2D(_MainTex, i.uv);
    43. #if INVERT_ON
    44.             col = 1 - col;
    45. #endif
    46.                 return col;
    47.             }
    48.             ENDCG
    49.         }
    50.     }
    51. }
    52.  
    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
     
  2. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    100
    submitted bug report

    (Case 892777) shader feature will always NOT toggled ON in mobile build, only when UsePass is used
     
  3. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    100