Search Unity

Shader failing to compile for tvOS

Discussion in 'Shaders' started by manny003, Apr 17, 2016.

  1. manny003

    manny003

    Joined:
    Mar 18, 2014
    Posts:
    70
    I have a shader that I've been using successfully on a released game for both the iPad and iPhone. However, I've been testing the same app for my tvOS Build and the shader is failing and the rendering is not correct.

    It's a simple shader that I use for vertical scrolling background that uses two textures. Texture 1 is a plain 2d image that I use for the background. Texture 2 is a simple gradient that I use to smoothly fade the background image to black (or whatever the current camera background color is). There is also an optional Color Property that I use to tint the main 2d texture image.

    Here is the shader code that I got from the internet and modified (don't remember where -- it's been a while):

    Code (csharp):
    1.  
    2. // Unlit alpha-blended shader.
    3. // - no lighting
    4. // - no lightmap support
    5. // - no per-material color
    6. Shader "Custom/Unlit/TransparentWithAlpha" {
    7.     Properties {
    8.         _Color ("Main Color", Color) = (1,1,1,1)
    9.         _MainTex ("Base (RGB)", 2D) = "white" {}
    10.         _AlphaTex ("Alpha mask (R)", 2D) = "white" {}
    11.     }
    12.     SubShader {
    13.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    14.         LOD 200
    15.  
    16.         Blend SrcAlpha OneMinusSrcAlpha
    17.  
    18.         Pass {
    19.             CGPROGRAM
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.  
    23.             #include "UnityCG.cginc"
    24.  
    25.             struct appdata_t {
    26.                 float4 vertex : POSITION;
    27.                 float2 texcoord : TEXCOORD0;
    28.                 float2 texcoord1 : TEXCOORD1;
    29.             };
    30.  
    31.             struct v2f {
    32.                 float4 vertex : SV_POSITION;
    33.                 half2 texcoord : TEXCOORD0;
    34.                 half2 texcoord1 : TEXCOORD1;
    35.             };
    36.            
    37.             float4 _Color;
    38.             sampler2D _MainTex;
    39.             sampler2D _AlphaTex;
    40.  
    41.             float4 _MainTex_ST;
    42.             float4 _AlphaTex_ST;
    43.  
    44.             v2f vert (appdata_t v) {
    45.                 v2f o;
    46.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    47.                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    48.                
    49.                 o.texcoord1 = TRANSFORM_TEX(v.texcoord1, _AlphaTex);
    50.                
    51.                 return o;
    52.             }
    53.            
    54.             fixed4 frag (v2f i) : SV_Target {
    55.                 fixed4 col = tex2D(_MainTex, i.texcoord) * _Color;
    56.                 fixed4 col2 = tex2D(_AlphaTex, i.texcoord1) * _Color.a;
    57.  
    58.                 return fixed4(col.r, col.g, col.b, col2.r);
    59.             }
    60.             ENDCG
    61.         }
    62.     }
    63. }

    As you can see, I hoped it was a simple shader and its been working ok in iPad and iPhone. However, in tvOS Simulator and actual device, the background image does not appear and Xcode is throwing the following errors:

    Code (csharp):
    1.  
    2. -------- Shader compilation failed
    3. #version 300 es
    4. precision highp float;
    5. #define UNITY_NO_DXT5nm 1
    6. #define UNITY_NO_RGBM 1
    7. #define UNITY_NO_SCREENSPACE_SHADOWS 1
    8. #define UNITY_NO_LINEAR_COLORSPACE 1
    9. #define UNITY_ENABLE_REFLECTION_BUFFERS 1
    10. #define UNITY_FRAMEBUFFER_FETCH_AVAILABLE 1
    11. #define UNITY_PBS_USE_BRDF2 1
    12. #define SHADER_API_MOBILE 1
    13. #ifndef SHADER_TARGET
    14.     #define SHADER_TARGET 30
    15. #endif
    16. #ifndef SHADER_API_GLES3
    17.     #define SHADER_API_GLES3 1
    18. #endif
    19. #line 17
    20. #ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
    21. #endif
    22. #line 17
    23. #ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
    24. #endif
    25.             varying mediump vec2 uv;
    26.  
    27.              
    28.                
    29.            
    30. #define gl_ModelViewProjectionMatrix glstate_matrix_mvp
    31. uniform highp mat4 glstate_matrix_mvp;
    32. #define gl_Vertex _glesVertex
    33. in vec4 _glesVertex;
    34. #define gl_MultiTexCoord0 _glesMultiTexCoord0
    35. in vec4 _glesMultiTexCoord0;
    36.    uniform mediump vec4 _MainTex_ST;
    37.       void main() {
    38.           gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    39.           uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
    40.       }
    41. -------- failed compiling:
    42. vertex shader
    43. -------- Shader compilation failed
    44. #version 300 es
    45. precision highp float;
    46. #define UNITY_NO_DXT5nm 1
    47. #define UNITY_NO_RGBM 1
    48. #define UNITY_NO_SCREENSPACE_SHADOWS 1
    49. #define UNITY_NO_LINEAR_COLORSPACE 1
    50. #define UNITY_ENABLE_REFLECTION_BUFFERS 1
    51. #define UNITY_FRAMEBUFFER_FETCH_AVAILABLE 1
    52. #define UNITY_PBS_USE_BRDF2 1
    53. #define SHADER_API_MOBILE 1
    54. #ifndef SHADER_TARGET
    55.     #define SHADER_TARGET 30
    56. #endif
    57. #ifndef SHADER_API_GLES3
    58.     #define SHADER_API_GLES3 1
    59. #endif
    60. #line 17
    61. #ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
    62. #endif
    63. #line 17
    64. #ifdef DUMMY_PREPROCESSOR_TO_WORK_AROUND_HLSL_COMPILER_LINE_HANDLING
    65. #endif
    66.             varying mediump vec2 uv;
    67.  
    68.              
    69.                
    70.            
    71. #define gl_FragColor _glesFragColor
    72. layout(location = 0) out mediump vec4 _glesFragColor;
    73.             uniform lowp sampler2D _MainTex;
    74.             uniform lowp vec4 _Color;
    75.             void main() {
    76.                 gl_FragColor = texture(_MainTex, uv) * _Color;
    77.             }
    78. -------- failed compiling:
    79. fragment evaluation shader
    80. Note: Creation of internal variant of shader 'Custom/Unlit/Transparent' failed.
    81. -------- Shader compilation failed
    82.  

    It repeats so I don't really know where it begins or ends.

    I've tried everything I can think of but I'm not a shader programmer by any stretch.

    Can someone help me solve?

    Thanks,
    Manny
     
  2. manny003

    manny003

    Joined:
    Mar 18, 2014
    Posts:
    70
    Never mind. I posted with wrong info. How to I delete a thread?