这是我尝试使用的片段着色器代码(在 OpenGL ES 2.0、OpenGLES GLSL ES 1.00 中):
GLchar strFragmentShader[] =
"precision mediump float; \n"
"varying vec2 vTexCoord; \n"
"uniform sampler2D sTexture; \n"
"uniform float offset[] = float[]( 0.0000, 1.3846, 3.2307); \n"
"uniform float weight[] = float[]( 0.2270, 0.3162, 0.0702); \n"
"void main() \n"
"{ \n"
" vec4 sum = texture2D( sTexture, vec2(vTexCoord)/1024.0)*weight[0]; \n"
" for (int i=0;i<3;i++) { \n"
" sum += texture2D( sTexture, ( vec2(vTexCoord+vec2(0.0,offset[i])/1024.0 )*weight[i]; \n"
" sum += texture2D( sTexture, ( vec2(vTexCoord-vec2(0.0,offset[i])/1024.0 )*weight[i]; \n"
" } \n"
" gl_FragColor = sum; \n"
"} \n";
我基本上遵循此页面上的示例,但我明白了ERROR:LEX/PARSE-1 (fragment shader, line 4) Syntax error
。
如果我尝试将它们声明为const
而不是此处uniform
建议的(在数组构造函数下),我会得到. ERROR:CUSTOM-5 (fragment shader, line 4) Array cannot be const
显然第 4 行和第 5 行会有同样的问题。我如何让它编译?什么是正确的语法?