在Android上将GLE2S0着色器转换为GLES30

时间:2016-09-14 10:19:11

标签: android opengl-es

我有一个基于GLES20的代码,现在当我尝试使用GLES30时,代码不起作用。

我已经尝试使用THIS指南这样做,但它仍然无效。

我相信也许我在这里错过了一些东西。

这是基于GLES20的“着色器”代码:

private static final String VERTEX_SHADER =
    "uniform mat4 uMVPMatrix;\n" +
    "uniform mat4 uSTMatrix;\n" +
    "attribute vec4 aPosition;\n" +
    "attribute vec4 aTextureCoord;\n" +
    "varying vec2 vTextureCoord;\n" +
    "void main() {\n" +
    "    gl_Position = uMVPMatrix * aPosition;\n" +
    "    vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
    "}\n";

private static final String FRAGMENT_SHADER =
    "#extension GL_OES_EGL_image_external : require\n" +
    "precision mediump float;\n" +      // highp here doesn't seem to matter
    "varying vec2 vTextureCoord;\n" +
    "uniform samplerExternalOES sTexture;\n" +
    "void main() {\n" +
    "    vec4 tc = texture2D(sTexture, vTextureCoord);\n" +
    "    gl_FragColor.r = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
    "    gl_FragColor.g = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
    "    gl_FragColor.b = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
    "}\n";

在此代码中,我从录制的视频中获取了一个帧,并将每个RPB频道转换为灰度。

有人可以帮我转换使用GLES30吗?

更新1:

private static final String VERTEX_SHADER =
        "#version 300 es\n"+
        "uniform mat4 uMVPMatrix;\n" +
        "uniform mat4 uSTMatrix;\n" +
        "in  vec4 aPosition;\n" +
        "in  vec4 aTextureCoord;\n" +
        "out vec2 vTextureCoord;\n" +
        "void main() {\n" +
        "    gl_Position = uMVPMatrix * aPosition;\n" +
        "    vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
        "}\n";

private static final String FRAGMENT_SHADER =
        "#version 300 es\n"+
        "#extension GL_OES_EGL_image_external : require\n" +
        "precision mediump float;\n" +      // highp here doesn't seem to matter
        "out vec3 vTextureCoord;\n" +
        "uniform samplerExternalOES sTexture;\n" +
        "void main() {\n" +
        "    vec4 tc = texture2D(sTexture, vTextureCoord);\n" +
        "    gl_FragColor.r = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    gl_FragColor.g = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    gl_FragColor.b = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "}\n";

更新2:

下面的代码可以工作,但我输出缓冲区中只有零

private static final String VERTEX_SHADER =
        "#version 300 es\n"+
        "uniform mat4 uMVPMatrix;\n" +
        "uniform mat4 uSTMatrix;\n" +
        "in  vec4 aPosition;\n" +
        "in  vec4 aTextureCoord;\n" +
        "out vec2 vTextureCoord;\n" +
        "void main() {\n" +
        "    gl_Position = uMVPMatrix * aPosition;\n" +
        "    vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
        "}\n";

private static final String FRAGMENT_SHADER =
        "#version 300 es\n"+
        "#extension GL_OES_EGL_image_external_essl3 : require\n" +
        "precision mediump float;\n" +      // highp here doesn't seem to matter
        "in vec2 vTextureCoord;\n" +
        "uniform sampler2D sTexture;\n" +
        "out vec4 fragColor ;\n" +
        "void main() {\n" +
        "    vec4 tc = texture(sTexture, vTextureCoord);\n" +
        "    fragColor .r = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    fragColor .g = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "    fragColor .b = tc.r * 0.3 + tc.g * 0.59 + tc.b * 0.11;\n" +
        "}\n";

0 个答案:

没有答案