我正在使用GLSL。
我在这里有一个简单的片段着色器:
"uniform sampler2D backBuffer;",
"uniform float r;",
"uniform float g;",
"uniform float b;",
"uniform float ratio;",
"void main() {",
" vec4 color;",
" float avg, dr, dg, db, multiplier;",
" color = texture2D(backBuffer, vec2(gl_TexCoord[0].x * 1,gl_TexCoord[0].y * 1));",
" avg = (color.r + color.g + color.b) / 3.0;",
" dr = avg * r;",
" dg = avg * g;",
" db = avg * b;",
" color.r = color.r * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" color.g = color.g * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" color.b = color.b * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" gl_FragColor = color;",
"}"
现在它工作得很好。
然而,由于一些非常奇怪的原因,添加更多的变量(如vec2或float)会导致它对我的场景没有影响:
"uniform sampler2D backBuffer;",
"uniform float r;",
"uniform float g;",
"uniform float b;",
"uniform float ratio;",
"void main() {",
" vec4 color;",
" float avg, dr, dg, db, multiplier;",
" vec2 divisors;",
" color = texture2D(backBuffer, vec2(gl_TexCoord[0].x * 1,gl_TexCoord[0].y * 1));",
" avg = (color.r + color.g + color.b) / 3.0;",
" dr = avg * r;",
" dg = avg * g;",
" db = avg * b;",
" color.r = color.r * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" color.g = color.g * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" color.b = color.b * (gl_TexCoord[0].x * gl_TexCoord[0].y);",
" gl_FragColor = color;",
"}"
在这个例子中,我添加了一个称为除数的vec2,这就是我所做的,着色器不再对像素做任何事情。
为什么会这样?关于GLSL中的变量声明,我有什么不理解的地方吗?
谢谢