1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Reddit AMA with Adam Myhill on Cinemachine, Thurs July 27 - 10AM PT. More info.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  7. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    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:
    118
    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:
    118
    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:
    118
  4. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    118
    confirmed is a bug(received email from UnityQA), is there any workaround currently?

    because the email said