4

我正在尝试使用 GLSL 的着色器,但是当我尝试从纹理中获取数据以尝试简单的对比度增强算法时,我遇到了一个有趣的错误。

'texture2D' : no matching overloaded function found 

这段代码会发生这种情况,其中“final”是 vec4 变量,用于保存正在处理的颜色。这里的想法是将像素的颜色从周围的颜色推得更远(一个实验性的想法)。我会在代码中有错误的那一行做标记。

highp vec4 tex = texture2D(tex,vec2(texcoord.x+1.0,texcoord.y));
highp float total = tex.r + tex.g + tex.b;
tex = texture2D(tex,vec2(texcoord.x-1.0,texcoord.y)); <----This one as well as the next similar lines
total += tex.r + tex.g + tex.b;
tex = texture2D(tex,vec2(texcoord.x,texcoord.y+1.0));
total += tex.r + tex.g + tex.b;
tex = texture2D(tex,vec2(texcoord.x,texcoord.y-1.0));
total += tex.r + tex.g + tex.b;
highp float di = 12.0;
highp vec4 close_av = total/di;
final = (final - close_av)*1.3+close_av;

为什么它不起作用?谢谢你。

4

1 回答 1

7

假设它tex最初uniform sampler2D在着色器源代码的顶部声明为 a ,它被代码片段的第一行重新声明为局部变量,这隐藏了原始定义。更改任一变量以使其名称不同应该可以解决您的编译问题。

于 2011-01-29T06:06:07.240 回答