【问题标题】:Unity Android Shader not supported on some devices某些设备不支持 Unity Android 着色器
【发布时间】:2015-07-17 15:51:03
【问题描述】:

我有一个使用自定义着色器进行视频播放的 Unity 应用。在某些设备上,视频未显示,并且我在 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 so we can access the 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 any 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

着色器代码如下:

Shader "Custom/AndroidVideoShader" {
Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
    Pass{


    GLSLPROGRAM

    varying vec2 textureCoordinates;

    #ifdef VERTEX

    // get the texture offset ftom our material
    uniform mediump vec4 _MainTex_ST;

    void main()
    {
        // multiply the UV by texture scale and add the 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 so we can access the 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"
}

这似乎不是 android 版本的东西,因为我收到错误的设备(客户端的 Note 2 和 Huawei Ascend Y330)运行不同版本的 Android(分别为 4.4.2 和 4.2.2)。我有一个 Nexus 7 (4.2.2)、Xperia M2 (4.4.4) 和 Galaxy Tab 8.4 (5.1.1),它们都可以正常工作。

我在着色器方面没有经验 - 有什么明显的问题会导致问题吗?在 Unity 中,我尝试将图形级别设置为 OpenGLES2.0 和 OpenGLES3.0,但没有任何区别。

【问题讨论】:

    标签: android unity3d opengl-es shader


    【解决方案1】:

    这是着色器中的语法错误,

    GLSL error: 0:23: P0007: Extension directive must occur before any non-preprocessor tokens
    

    这在 ESSL 规范中是不合法的:

    #extension GL_OES_EGL_image_external : require
    

    ... 定义在:

    varying vec2 textureCoordinates;
    

    它在某些设备上完全有效的原因只是运气 - 一些着色器编译器比其他编译器不那么挑剔。更改着色器,使#extension 定义成为源代码中的第一件事,然后它应该一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多