unity3d - Unity Android Shader not supported on some devices -


i have unity app uses custom shader video playback. on devices video isn't shown , following error message printed out in logcat:

e/unity   (11415): -------- custom/androidvideoshader e/unity   (11415):  e/unity   (11415):   e/unity   (11415): (filename: runtime/gfxdevice/opengles/glslgpuprogramgles.cpp line: 141) e/unity   (11415):  e/unity   (11415): -------- failed compiling fragment shader: e/unity   (11415):  e/unity   (11415):   e/unity   (11415): (filename: runtime/gfxdevice/opengles/glslgpuprogramgles.cpp line: 142) e/unity   (11415):  d/unity   (11415): #ifndef shader_api_gles d/unity   (11415):     #define shader_api_gles 1 d/unity   (11415): #endif d/unity   (11415): #ifndef shader_api_mobile d/unity   (11415):     #define shader_api_mobile 1 d/unity   (11415): #endif d/unity   (11415): #line 7 d/unity   (11415): #ifdef dummy_preprocessor_to_work_around_hlsl_compiler_line_handling d/unity   (11415): #endif d/unity   (11415): #line 7 d/unity   (11415): #ifdef dummy_preprocessor_to_work_around_hlsl_compiler_line_handling d/unity   (11415): #endif d/unity   (11415):      precision mediump float; d/unity   (11415): varying vec2 texturecoordinates; d/unity   (11415):       d/unity   (11415):       d/unity   (11415):       d/unity   (11415):       d/unity   (11415):   // require gl_oes_egl_image_external can access external texture data on android's gpu d/unity   (11415):   #extension gl_oes_egl_image_external : require d/unity   (11415):   uniform samplerexternaloes _maintex; d/unity   (11415):   void main() d/unity   (11415):   { d/unity   (11415):    gl_fragcolor = texture2d(_maintex, texturecoordinates); d/unity   (11415):   } d/unity   (11415):    d/unity   (11415):    e/unity   (11415): -------- glsl error: 0:23: p0007: extension directive must occur before non-preprocessor tokens e/unity   (11415): 0:25: l0001: typename expected, found 'samplerexternaloes' e/unity   (11415):  e/unity   (11415):  e/unity   (11415):  e/unity   (11415):   e/unity   (11415): (filename: runtime/gfxdevice/opengles/glslgpuprogramgles.cpp line: 145) e/unity   (11415):  d/unity   (11415): warning: creation of shader 'custom/androidvideoshader' failed. d/unity   (11415): warning: shader  d/unity   (11415): unsupported: 'custom/androidvideoshader' - pass '' shader state not supported 

the shader code follows:

shader "custom/androidvideoshader" { properties {     _maintex ("base (rgb)", 2d) = "white" {} } subshader {     pass{       glslprogram      varying vec2 texturecoordinates;      #ifdef vertex      // texture offset ftom our material     uniform mediump vec4 _maintex_st;      void main()     {         // multiply uv texture scale , add offset         texturecoordinates.xy = (gl_multitexcoord0.xy * _maintex_st.xy) + _maintex_st.zw;          //texturecoordinates = gl_multitexcoord0;          gl_position = gl_modelviewprojectionmatrix * gl_vertex;     }      #endif       #ifdef fragment      // require gl_oes_egl_image_external can access external texture data on android's gpu     #extension gl_oes_egl_image_external : require      uniform samplerexternaloes _maintex;      void main()     {         gl_fragcolor = texture2d(_maintex, texturecoordinates);     }      #endif      endglsl     } }  fallback "diffuse" } 

it doesn't seem android version thing devices error on (a client's note 2 , huawei ascend y330) running different versions of android (4.4.2 , 4.2.2 respectively). have nexus 7 (4.2.2), xperia m2 (4.4.4) , galaxy tab 8.4 (5.1.1) work no problems.

i'm not experienced in shaders - there obvious that's causing problem? in unity i've tried setting graphics level opengles2.0 , opengles3.0 doesn't make difference.

it's syntax error in shader,

glsl error: 0:23: p0007: extension directive must occur before non-preprocessor tokens 

it isn't legal in essl specification for:

#extension gl_oes_egl_image_external : require 

... defined after:

varying vec2 texturecoordinates; 

the reason works @ on devices luck - shader compilers less picky others. change shader #extension definition first thing in source, , should work fine.


Comments