Search Unity

[FIXED] Unity 5.6.1f1 build fail (Android) shader error possible cause

Discussion in 'Editor & General Support' started by vincent-savysoda, May 24, 2017.

  1. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    33
    Hi I just updated my unity client to 5.6.1f1 today and I am now unable to build to my android device. I also received the following errors:

    Screen Shot 2017-05-24 at 11.37.30 AM.png

    The following is code is the shader script that the error is occuring on:

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. Shader "Unlit/Texture HSBC" {
    4.     Properties
    5.     {
    6.         //[PerRendererData] _MainTex ("Sprite Texture", 2D) = "black" {}
    7.         _MainTex("Base (RGB), Alpha (A)", 2D) = "black" {}
    8.         _Hue("Hue", Range(0.0, 1.0)) = 0
    9.         _Saturation("Saturation", Range(-1.0, 1.0)) = 0
    10.         _Brightness("Brightness", Range(-1.0, 1.0)) = 0
    11.         _Contrast("Contrast", Range(-1.0, 1.0)) = 0
    12.         _StencilComp ("Stencil Comparison", Float) = 8
    13.         _Stencil ("Stencil ID", Float) = 0
    14.         _StencilOp ("Stencil Operation", Float) = 0
    15.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    16.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    17.         _ColorMask ("Color Mask", Float) = 15
    18.         //[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    19.     }
    20.     SubShader
    21.     {
    22.         LOD 100
    23.         Tags
    24.         {
    25.             "Queue"="Transparent"
    26.             "IgnoreProjector"="True"
    27.             "RenderType"="Transparent"
    28.             "PreviewType"="Plane"
    29.             "CanUseSpriteAtlas"="True"
    30.         }
    31.         Cull Off
    32.         Lighting Off
    33.         ZWrite Off
    34.         Fog{ Mode Off }
    35.         Offset -1, -1
    36.         Blend SrcAlpha OneMinusSrcAlpha
    37.  
    38.         Pass
    39.         {
    40.             CGPROGRAM
    41.             #pragma vertex vert
    42.             #pragma fragment frag
    43.             #include "UnityCG.cginc"
    44.             // Function
    45.             inline float3 applyHue(float3 aColor, float aHue)
    46.             {
    47.                 float angle = radians(aHue);
    48.                 float3 k = float3(0.57735, 0.57735, 0.57735);
    49.                 float cosAngle = cos(angle);
    50.                 //Rodrigues' rotation formula
    51.                 return aColor * cosAngle + cross(k, aColor) * sin(angle) + k * dot(k, aColor) * (1 - cosAngle);
    52.             }
    53.             inline float4 applyHSBEffect(float4 startColor, fixed4 hsbc)
    54.             {
    55.                 float hue = 360 * hsbc.r;
    56.                 float saturation = hsbc.g + 1;
    57.                 float brightness = hsbc.b;
    58.                 float contrast = hsbc.a + 1;
    59.                 float4 outputColor = startColor;
    60.                 outputColor.rgb = applyHue(outputColor.rgb, hue);
    61.                 outputColor.rgb = (outputColor.rgb - 0.5f) * contrast + 0.5f + brightness;
    62.                 outputColor.rgb = lerp(Luminance(outputColor.rgb), outputColor.rgb, saturation);
    63.    
    64.                 return outputColor;
    65.             }
    66.             struct appdata_t
    67.             {
    68.                 float4 vertex : POSITION;
    69.                 float2 texcoord : TEXCOORD0;
    70.                 fixed4 color : COLOR;
    71.             };
    72.             struct v2f
    73.             {
    74.                 float4 vertex : SV_POSITION;
    75.                 half2 texcoord : TEXCOORD0;
    76.                 fixed4 hsbc : COLOR;
    77.                 float alpha : float;
    78.             };
    79.             sampler2D _MainTex;
    80.             fixed _Hue, _Saturation, _Brightness, _Contrast;
    81.             v2f vert(appdata_t v)
    82.             {
    83.                 v2f o;
    84.                 o.vertex = UnityObjectToClipPos(v.vertex);
    85.                 o.texcoord = v.texcoord;
    86.                 o.hsbc = fixed4(_Hue, _Saturation, _Brightness, _Contrast);
    87.                 o.alpha = v.color.a;
    88.                 return o;
    89.             }
    90.             fixed4 frag(v2f i) : COLOR
    91.             {
    92.                 float4 startColor = tex2D(_MainTex, i.texcoord);
    93.                 float4 hsbColor = applyHSBEffect(startColor, i.hsbc);
    94.                 hsbColor.a *= i.alpha;
    95.                 return hsbColor;
    96.             }
    97.             ENDCG
    98.         } // Pass
    99.     } // SubShader
    100.     SubShader
    101.     {
    102.         LOD 100
    103.         Tags
    104.         {
    105.             "Queue"="Transparent"
    106.             "IgnoreProjector"="True"
    107.             "RenderType"="Transparent"
    108.             "PreviewType"="Plane"
    109.             "CanUseSpriteAtlas"="True"
    110.         }
    111.  
    112.         Pass
    113.         {
    114.             Cull Off
    115.             Lighting Off
    116.             ZWrite Off
    117.             Fog{ Mode Off }
    118.             Offset -1, -1
    119.             ColorMask RGB
    120.             //AlphaTest Greater .01
    121.             Blend SrcAlpha OneMinusSrcAlpha
    122.             ColorMaterial AmbientAndDiffuse
    123.             SetTexture[_MainTex] { Combine Texture * Primary }
    124.         } // Pass
    125.     } // SubShader
    126. }
    EDIT: The offending bit of code is line 77 here, not line 87.

    As I'm not a shader programmer I have no idea how to fix this issue correctly. Does anyone know how to resolve this?

    Additional Info: The shader was meant to allow my 2D sprite images to use HSB colors instead of Unity's default HSV/HSL. It also needs to be able to accept any alpha changes to the image


    UPDATE:
    In other news I'm also getting this error
    but this hasn't caused an issue before as well. This is the line of code in the projects settings that is causing the issue:

    I've tried changing it to just {fileID: 1} but that only worked temporarily as it eventually just resets itself back to the above

    UPDATE 2:
    Removing the splash screen image seems to have fixed that error. I still have the shader error preventing me from making a build though.
     
    Last edited: May 24, 2017
  2. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    33
    Ok after playing around a bit it seems like the Unity 5.6.1f1 update is now completely preventing the build if there are ANY errors at all, even if those errors had previously been allowed to work in the previous versions.