0

setShaders

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

useProgram

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

vars

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};

FragmentShader

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

then trying to reach: weight[i]

I get this:

Shader log: 0:13: S0004: Member reference or swizzle attempted on non-structure and non-vector

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

(i = 0 to 2)

so my question: How to bypassing a float array to a uniform? float[3]

the code

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";
2
  • Can we see the line that's actually causing the error? Commented Jun 14, 2012 at 9:13
  • tc += texture2D(uFrameBufferTexture, vTextureCoord[0].xy + vec2(0.0, offset[i])/uScreenHeight).rgb * weight[i]; Commented Jun 14, 2012 at 9:15

2 Answers 2

3

The problem isn't actually with weight or offset. The compiler is complaining that you say vTextureCoord[0].xy, but you declared vTextureCoord as varying vec2 vTextureCoord;.

Either declare vTextureCoord as an array, or don't say [0].

Sign up to request clarification or add additional context in comments.

1 Comment

varying vec2 vTextureCoord[1]; (or whatever you need instead of 1)
1

You don't need to declare it as an array, but if you want you can simply use:

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

Also, don't forget to modify the varying the the vertex shader too so that they will be identical.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.