2012-06-14 86 views
0

setShadersGLSL旁路浮陣列均勻

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

useProgram

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

FragmentShader

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

然後試圖達成:重量[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"; 
+0

我們可以看到實際上導致錯誤的行嗎? – moonshadow

+0

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

回答

2

的問題是不實際與weightoffset。編譯器抱怨說你說vTextureCoord[0].xy,但你宣稱vTextureCoordvarying vec2 vTextureCoord;

要麼聲明vTextureCoord作爲數組,要麼聲明[0]

+0

好吧,如何聲明爲一個數組vTextCoord? – lacas

+0

'變化vec2 vTextureCoord [1];'(或任何你需要的而不是1) – moonshadow

1

你不需要把它聲明爲一個數組,但如果你願意,你可以簡單地使用:

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

另外,不要忘了修改改變頂點着色器也讓他們將是相同的。