Search Unity

Shaders not working on iOS

Discussion in 'Shaders' started by theJulman, Nov 24, 2018.

  1. theJulman

    theJulman

    Joined:
    Jun 29, 2014
    Posts:
    4
    Hi,
    I have to convert an existing unity VR project (that works fine on android) to iOS, but every object with two specific shaders is rendered black. The two Shaders are "Blend" and "Over", and in XCode I can see this error:

    ERROR: 0:66: int can't be an in in the fragment shader
    ERROR: 0:78: Use of undeclared identifier 'xlv_TEXCOORD2'

    Note: Creation of internal variant of shader 'CustomRenderTexture/Blend' failed.
    WARNING: Shader Unsupported: 'CustomRenderTexture/Blend' - Pass '' has no vertex shader
    ERROR: Shader Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    WARNING: Shader Unsupported: 'CustomRenderTexture/Blend' - Setting to default shader.
    ERROR: 0:52: '' :extension 'GL_EXT_gpu_shader4' is not supported

    ERROR: 0:47: int can't be an in in the fragment shader
    ERROR: 0:59: Use of undeclared identifier 'xlv_TEXCOORD2'

    Note: Creation of internal variant of shader 'CustomRenderTexture/Over' failed.
    WARNING: Shader Unsupported: 'CustomRenderTexture/Over' - Pass '' has no vertex shader
    ERROR: Shader Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    WARNING: Shader Unsupported: 'CustomRenderTexture/Over' - Setting to default shader.

    I'm a total beginner when it comes to shaders. Do I maybe have to force shader building for iOS somewhere?

    Thanks in advance
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Post the shader code, but I suspect you have a v2f struct with one of the values defined as an int?
     
  3. theJulman

    theJulman

    Joined:
    Jun 29, 2014
    Posts:
    4
    This is the pass code for "Blend":

    Code (CSharp):
    1. CGPROGRAM
    2.             #include "UnityCustomRenderTexture.cginc"
    3.             #pragma vertex CustomRenderTextureVertexShader
    4.             #pragma fragment frag
    5.             #pragma target 3.0
    6.  
    7.             float _BlendMode;
    8.             float _Blend;
    9.             sampler2D _ATex, _BTex;
    10.             float4 _ATex_ST, _BTex_ST;
    11.             float _PremultipliedBlend;
    12.            
    13.             fixed4 frag (v2f_customrendertexture IN) : Color
    14.             {
    15.                 // sample the textures
    16.                 float2 uvA = TRANSFORM_TEX(IN.localTexcoord.xy, _ATex);
    17.                 float2 uvB = TRANSFORM_TEX(IN.localTexcoord.xy, _BTex);
    18.                 fixed4 colA = tex2D(_ATex, uvA);
    19.                 fixed4 colB = tex2D(_BTex, uvB);
    20.  
    21.                 if(_BlendMode == 1) {
    22.                     // Add
    23.                     if(_PremultipliedBlend) {
    24.                         colA *= (1.0 - colB.a * _Blend);
    25.                         colB *= colB.a * _Blend;
    26.                     }
    27.                     return colA + colB;
    28.                 } else if(_BlendMode == 2) {
    29.                     // Substract
    30.                     if(_PremultipliedBlend) {
    31.                         colA *= (1.0 - colB.a * _Blend);
    32.                         colB *= colB.a * _Blend;
    33.                     }
    34.                     return colA - colB;
    35.                 } else {
    36.                     // Replace
    37.                     return lerp(colA, colB, _Blend);
    38.                 }
    39.             }
    And this is the pass code for "Over":

    Code (CSharp):
    1. CGPROGRAM
    2.             #include "UnityCustomRenderTexture.cginc"
    3.             #pragma vertex CustomRenderTextureVertexShader
    4.             #pragma fragment frag
    5.             #pragma target 3.0
    6.  
    7.             sampler2D _BGTex, _FGTex;
    8.             float4 _BGTex_ST, _FGTex_ST;
    9.             float _PremultipliedOver;
    10.            
    11.             fixed4 frag (v2f_customrendertexture IN) : Color
    12.             {
    13.                 // sample the textures
    14.                 float2 uvBG = TRANSFORM_TEX(IN.localTexcoord.xy, _BGTex);
    15.                 float2 uvFG = TRANSFORM_TEX(IN.localTexcoord.xy, _FGTex);
    16.                 fixed4 colFG = tex2D(_FGTex, uvFG);
    17.                 fixed4 colBG = tex2D(_BGTex, uvBG);
    18.                 colBG.rgb *= 1.0 - colFG.a;
    19.                 if(_PremultipliedOver) {
    20.                     colFG.rgb *= colFG.a;
    21.                 }
    22.                 return colBG + colFG;
    23.             }
    Both using Unity's CustomRenderTexture on version 2017.3
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You need to post the entire shader file. The error is not in the section you posted.
     
  5. theJulman

    theJulman

    Joined:
    Jun 29, 2014
    Posts:
    4
    Entire "Blend" shader:
    Code (CSharp):
    1. Shader "CustomRenderTexture/Blend"
    2. {
    3.     Properties
    4.     {
    5.         [KeywordEnum(Replace, Add, Substract)] _BlendMode ("Blend Mode", Float) = 0
    6.         _Blend ("Blend", Range (0, 1)) = 0
    7.         _ATex ("Texture A", 2D) = "black" {}
    8.         _BTex ("Texture B", 2D) = "black" {}
    9.         [MaterialToggle] _PremultipliedBlend("Blend Premultiplied", Float) = 1
    10.     }
    11.     SubShader
    12.     {
    13.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    14.  
    15.         Lighting Off
    16.         //Blend SrcAlpha OneMinusSrcAlpha
    17.         Blend One Zero
    18.  
    19.         LOD 100
    20.  
    21.         Pass
    22.         {
    23.             CGPROGRAM
    24.             #include "UnityCustomRenderTexture.cginc"
    25.             #pragma vertex CustomRenderTextureVertexShader
    26.             #pragma fragment frag
    27.             #pragma target 3.0
    28.  
    29.             float _BlendMode;
    30.             float _Blend;
    31.             sampler2D _ATex, _BTex;
    32.             float4 _ATex_ST, _BTex_ST;
    33.             float _PremultipliedBlend;
    34.            
    35.             fixed4 frag (v2f_customrendertexture IN) : Color
    36.             {
    37.                 // sample the textures
    38.                 float2 uvA = TRANSFORM_TEX(IN.localTexcoord.xy, _ATex);
    39.                 float2 uvB = TRANSFORM_TEX(IN.localTexcoord.xy, _BTex);
    40.                 fixed4 colA = tex2D(_ATex, uvA);
    41.                 fixed4 colB = tex2D(_BTex, uvB);
    42.  
    43.                 if(_BlendMode == 1) {
    44.                     // Add
    45.                     if(_PremultipliedBlend) {
    46.                         colA *= (1.0 - colB.a * _Blend);
    47.                         colB *= colB.a * _Blend;
    48.                     }
    49.                     return colA + colB;
    50.                 } else if(_BlendMode == 2) {
    51.                     // Substract
    52.                     if(_PremultipliedBlend) {
    53.                         colA *= (1.0 - colB.a * _Blend);
    54.                         colB *= colB.a * _Blend;
    55.                     }
    56.                     return colA - colB;
    57.                 } else {
    58.                     // Replace
    59.                     return lerp(colA, colB, _Blend);
    60.                 }
    61.             }
    62.             ENDCG
    63.         }
    64.     }
    65. }
    66.  
    Entire "Over" shader:
    Code (CSharp):
    1. Shader "CustomRenderTexture/Over"
    2. {
    3.     Properties
    4.     {
    5.         _BGTex ("Background Texture", 2D) = "black" {}
    6.         _FGTex ("Over Texture", 2D) = "black" {}
    7.         [MaterialToggle] _PremultipliedOver("Premultiplied Over", Float) = 1
    8.     }
    9.     SubShader
    10.     {
    11.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    12.  
    13.         Lighting Off
    14.         //Blend SrcAlpha OneMinusSrcAlpha
    15.         Blend One Zero
    16.  
    17.         LOD 100
    18.  
    19.         Pass
    20.         {
    21.             CGPROGRAM
    22.             #include "UnityCustomRenderTexture.cginc"
    23.             #pragma vertex CustomRenderTextureVertexShader
    24.             #pragma fragment frag
    25.             #pragma target 3.0
    26.  
    27.             sampler2D _BGTex, _FGTex;
    28.             float4 _BGTex_ST, _FGTex_ST;
    29.             float _PremultipliedOver;
    30.            
    31.             fixed4 frag (v2f_customrendertexture IN) : Color
    32.             {
    33.                 // sample the textures
    34.                 float2 uvBG = TRANSFORM_TEX(IN.localTexcoord.xy, _BGTex);
    35.                 float2 uvFG = TRANSFORM_TEX(IN.localTexcoord.xy, _FGTex);
    36.                 fixed4 colFG = tex2D(_FGTex, uvFG);
    37.                 fixed4 colBG = tex2D(_BGTex, uvBG);
    38.                 colBG.rgb *= 1.0 - colFG.a;
    39.                 if(_PremultipliedOver) {
    40.                     colFG.rgb *= colFG.a;
    41.                 }
    42.                 return colBG + colFG;
    43.             }
    44.             ENDCG
    45.         }
    46.     }
    47. }
    48.  
    The "UnityCustomRenderTexture.cginc" include is Unity's shader which you can view on Github (the first entry if you search for UnityCustomRenderTexture.cginc on Google)

    I didn't post the entire shader cause' I couldn't see any occurrences of integers in the section above. So the error will probably be in the "UnityCustomRenderTexture" shader, which is weird because i couldn't see any compatibility issues with iOS when i reasearched the problem.

    Maybe it helps too, if i post the entire error:

    2018-11-24 13:27:10.775972+0100 vrScene[785:271276] [DYMTLInitPlatform] platform initialization successful
    2018-11-24 13:27:11.027318+0100 vrScene[785:271165] -> registered mono modules 0xf32450
    -> applicationDidFinishLaunching()
    2018-11-24 13:27:11.399628+0100 vrScene[785:271165] Metal GPU Frame Capture Enabled
    2018-11-24 13:27:11.400452+0100 vrScene[785:271165] Metal API Validation Disabled
    -> applicationDidBecomeActive()
    Renderer: PowerVR SGX 543
    Vendor: Imagination Technologies
    Version: OpenGL ES 2.0 IMGSGX543-129
    GLES: 2
    GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_APPLE_texture_packed_float GL_IMG_read_format GL_IMG_texture_comp
    ression_pvrtc
    OPENGL LOG: Creating OpenGL ES 2.0 graphics device ; Context levelOpenGL ES 2.0 ; Context handle 383251264
    Initialize engine version: 2017.3.1f1 (fc1d3344e6ea)
    WARNING: 0:4: extension 'GL_EXT_frag_depth' is not supported
    ERROR: 0:38: Use of undeclared identifier 'gl_FragDepthEXT'
    Note: Creation of internal variant of shader 'Hidden/Internal-MotionVectors' failed.
    WARNING: Shader Unsupported: 'Hidden/Internal-MotionVectors' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/Internal-MotionVectors' - Setting to default shader.
    WARNING: Shader Unsupported: 'Hidden/BlitToDepth' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/BlitToDepth' - Setting to default shader.
    WARNING: Shader Unsupported: 'Hidden/BlitToDepth_MSAA' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/BlitToDepth_MSAA' - Setting to default shader.
    WARNING: 0:4: extension 'GL_EXT_frag_depth' is not supported
    ERROR: 0:14: Use of undeclared identifier 'gl_FragDepthEXT'
    Note: Creation of internal variant of shader 'Hidden/BlitCopyWithDepth' failed.
    WARNING: Shader Unsupported: 'Hidden/BlitCopyWithDepth' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/BlitCopyWithDepth' - Setting to default shader.
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySlice' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySlice' - Setting to default shader.
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySliceToDepth' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySliceToDepth' - Setting to default shader.
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySliceToDepth_MSAA' - Pass '' has no vertex shader
    WARNING: Shader Unsupported: 'Hidden/VR/BlitTexArraySliceToDepth_MSAA' - Setting to default shader.
    2018-11-24 13:27:12.936318+0100 vrScene[785:271165] INFO [vr/gvr/capi/src/gvr.cc:115] Initialized GVR version 1.100.0
    ERROR: 0:52: '' : extension 'GL_EXT_gpu_shader4' is not supported
    ERROR: 0:66: int can't be an in in the fragment shader
    ERROR: 0:78: Use of undeclared identifier 'xlv_TEXCOORD2'
    Note: Creation of internal variant of shader 'CustomRenderTexture/Blend' failed.
    WARNING: Shader Unsupported: 'CustomRenderTexture/Blend' - Pass '' has no vertex shader
    ERROR: Shader Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)WARNING: Shader Unsupported: 'CustomRenderTexture/Blend' - Setting to default shader.
    ERROR: 0:52: '' :extension 'GL_EXT_gpu_shader4' is not supported
    ERROR: 0:47: int can't be an in in the fragment shader
    ERROR: 0:59: Use of undeclared identifier 'xlv_TEXCOORD2'
    Note: Creation of internal variant of shader 'CustomRenderTexture/Over' failed.
    WARNING: Shader Unsupported: 'CustomRenderTexture/Over' - Pass '' has no vertex shader
    ERROR: Shader Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)WARNING: Shader Unsupported: 'CustomRenderTexture/Over' - Setting to default shader.
    Setting up 1 worker threads for Enlighten.
    UnloadTime: 5.219541 ms
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It looks like it's trying to compile the shaders using OpenGL ES 2.0? Custom Render Textures require OpenGL ES 3.1 AEP or OpenGL ES 3.2, neither of which iOS devices support. Only Metal has the features necessary to support Custom Render Textures, and it's possible it still doesn't work there due to a bug. I'd make sure your iOS player build target is set to only use Metal, and if that doesn't work submit a bug to Unity.
     
  7. theJulman

    theJulman

    Joined:
    Jun 29, 2014
    Posts:
    4
    Right, I tried to build with OpenGL ES 2.0. I try to build it with Metal API next.
    Thank you for your time and answers.
     
  8. Khoros

    Khoros

    Joined:
    Mar 1, 2016
    Posts:
    12
    thanks man! this solved the issue i was having with my customrendertexture!
     
  9. Sheriff_Xlebywek

    Sheriff_Xlebywek

    Joined:
    Nov 14, 2019
    Posts:
    1
    Can you please tell us in more detail what you did to fix the error on iOS?
     
  10. aubrian

    aubrian

    Joined:
    Apr 18, 2020
    Posts:
    8
    I would also greatly appreciate hearing more information on this. Thank you!
     
  11. Shreenath1322

    Shreenath1322

    Joined:
    Apr 7, 2016
    Posts:
    7
    What were the settings that fixed the issue... were the settings made in unity or in xcode?