【问题标题】:GLSL Compiler choosing wrong overloaded function?GLSL编译器选择错误的重载函数?
【发布时间】:2017-06-04 06:57:19
【问题描述】:

我正在尝试计算 GLSL 中高度图的表面法线。我基本上从 SO 答案 here 中复制了代码,并稍作改动以匹配我的变量:

77:                 float s01 = textureOffset(uTexture, uv, off.xy).x;
78:                 float s21 = textureOffset(uTexture, uv, off.zy).x;
79:                 float s10 = textureOffset(uTexture, uv, off.yx).x;
80:                 float s12 = textureOffset(uTexture, uv, off.yz).x;
81:                 vec3 va = normalize(vec3(size.xy, s21-s01));
82:                 vec3 vb = normalize(vec3(size.yx, s12-s10));
83:                 vec3 vNormal = cross(va,vb);

在哪里

uniform sampler2D   uTexture;
attribute vec2      uv;
const vec2          size = vec2(2.0, 0.0);
const ivec3         off = ivec3(-1, 0, 1);

问题是编译器返回错误:

THREE.WebGLProgram: shader error:  0 gl.VALIDATE_STATUS false gl.getProgramInfoLog invalid shaders ERROR: 0:77: 'textureOffset' : no matching overloaded function found
ERROR: 0:77: 'x' :  field selection requires structure or vector on left hand side
ERROR: 0:78: 'textureOffset' : no matching overloaded function found
ERROR: 0:78: 'x' :  field selection requires structure or vector on left hand side
ERROR: 0:79: 'textureOffset' : no matching overloaded function found
ERROR: 0:79: 'x' :  field selection requires structure or vector on left hand side
ERROR: 0:80: 'textureOffset' : no matching overloaded function found
ERROR: 0:80: 'x' :  field selection requires structure or vector on left hand side

编译器显然选择了错误的纹理偏移重载,但查看规范here,它看起来应该可以正常工作。所以......我错过了什么?我仍在研究,但对于 GLSL 新手的任何提示将不胜感激。 TIA。

注意:这是在 OSX 上使用 three.js r85

【问题讨论】:

  • 你重载的textureOffset的定义是什么样的?
  • 好吧,Khronos 网站(上面的链接)上显示的签名是 gvec4 textureOffset( gsampler2D sampler, vec2 P, ivec2 offset, [float bias]);我的电话(见上面的代码)似乎匹配。但我想知道是否可能为three.js 使用的着色器语言的WebGL 编译器不支持Khronos 网站上列出的完整的GLSL-ES 函数集。顺便说一句,我已经通过展开代码解决了这个问题,但我想在这里知道答案。
  • 对不起,我错过了您的规范链接,并误解了您使用的是内置方法。我以为你已经写了自己的重载。它可能在抱怨您的 off 参数的 const-ness。尝试从您的定义中删除const,或在您的函数调用中删除cast it non-const
  • 叹息。谢谢,这是个好主意。但我仍然得到同样的错误。更糟糕的是,我以为我可以通过自己进行偏移来解决这个问题,但后来(head-slap)意识到 uv 坐标在 0..1 并且偏移在纹素空间中,这是我自己做不到的(或者至少对我来说并不明显)。如果这是 C++,我会深入研究二进制文件和链接器内部,看看有什么问题,但是使用 GLSL 编译器我不知道从哪里开始。
  • 尝试转换所有参数。强迫它选择正确的。如果这不起作用,或者出现其他问题,则您的数据/值可能是错误的。

标签: compiler-errors three.js glsl vertex-shader


【解决方案1】:

查看 webgl 1.0 着色器的规范明确限制为不包括纹理偏移的着色器 glsl 规范 Es 1.0。

WebGL 2.0 可以使用包含 textureOffset 的 ES 3.0 着色器。

即您遇到的限制是 Webgl 1.0 规范规定的,而不是 browser/three.js/platform 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多