GLSL 'texture2D':在iPhone上的OpenGL ES2中找不到匹配的重载函数。

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;

为什么它不能工作?谢谢。
1个回答

7
假设在你的着色器源代码顶部将 `tex` 声明为 `uniform sampler2D`,则你的代码片段第一行重新声明它为局部变量,从而隐藏了原始定义。更改其中任意一个变量以保持它们的名称不同,应该可以解决编译问题。

3
谢谢。下次疲倦时我不会提出问题了。在清醒的时候很容易发现这些错误。 :) - Matthew Mitchell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接