0

setShaders

    muOffsetHandle = getUniformLocation("offset");      
    muWeightHandle = getUniformLocation("weight");

使用プログラム

    GLES20.glUniform1fv(muOffsetHandle, 1, mOffset, 0);
    GLES20.glUniform1fv(muWeightHandle, 1, mWeight, 0);

変数

private int muOffsetHandle;
private int muWeightHandle;

protected float mOffset[] =new float[] {0.0f, 1.3f, 3.3f}; 
protected float mWeight[] =new float[] {0.2f, 0.3f, 0.3f};

フラグメントシェーダー

        "uniform float offset[3];\n" +
        "uniform float weight[3];\n" +

次に到達しようとしています: weight[i]

私はこれを得る:

シェーダー ログ: 0:13: S0004: 非構造体および非ベクターでメンバー参照またはスウィズルが試行されました

13行目:tc += texture2D(uFrameBufferTexture, vTextureCoord[0].xy + vec2(0.0, offset[i])/uScreenHeight).rgb * weight[i];

(i=0~2)

だから私の質問:フロート配列をユニフォームにバイパスする方法は? フロート[3]

コード

protected static final String mFShader = 
        "precision mediump float;\n" +
        "varying vec2 vTextureCoord;\n" +
        "uniform float uTime;\n" +
        "uniform float uScreenWidth;\n" +
        "uniform float uScreenHeight;\n" +
        "uniform sampler2D uFrameBufferTexture;\n"+

        "uniform float offset[3];\n" +
        "uniform float weight[3];\n" +

        "void main() {\n"+
        "  vec3 tc = vec3(1.0, 0.0, 0.0);\n"+
        "  if (vTextureCoord[0].x<(uTime-0.01)) {\n"+
        "    tc = texture2D(uFrameBufferTexture, vTextureCoord[0].xy).rgb * weight[0];\n"+
        "    for (int i=1; i<3; i++) {\n"+
        "      tc += texture2D(uFrameBufferTexture, vTextureCoord[0].xy + vec2(0.0, offset[i])/uScreenHeight).rgb * weight[i];\n"+
        "      tc += texture2D(uFrameBufferTexture, vTextureCoord[0].xy - vec2(0.0, offset[i])/uScreenHeight).rgb * weight[i];\n"+
        "    }\n"+
        "  }\n"+
        "  else if (vTextureCoord[0].x>=(uTime+0.01)) {\n"+
        "    tc = texture2D(uFrameBufferTexture, vTextureCoord[0].xy).rgb;\n"+
        "  }\n"+
        "   gl_FragColor = vec4(tc, 1.0);\n"+
        "}\n";
4

2 に答える 2

3

問題は実際にはweightまたはではありませんoffset。コンパイラはあなたが言うと不平を言っていますが、あなたはとしてvTextureCoord[0].xy宣言しました。vTextureCoordvarying vec2 vTextureCoord;

配列として宣言するかvTextureCoord、言わないでください[0]

于 2012-06-14T09:24:33.003 に答える
1

配列として宣言する必要はありませんが、必要に応じて次を使用できます。

varying vec4 vTextureCoord[3]; // you can use anything you want between the brackets

また、それらが同一になるように、頂点シェーダーも変更することを忘れないでください。

于 2012-06-14T11:58:20.013 に答える