【问题标题】:no matching overloaded for function 'sqrt' found找不到函数“sqrt”的匹配重载
【发布时间】:2021-09-09 08:58:59
【问题描述】:

我的 glsl 文件出现此错误

no matching overloaded for function 'sqrt' found

这是我的以下代码

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D texture;

varying vec4 vertColor;
varying vec4 vertTexCoord;

uniform vec4 targetColor;
uniform float threshold; //between 0 and 1

void main() {
    vec4 texColor = texture2D(texture, vertTexCoord.st) * vertColor;
    vec3 a = texColor.xyz;
    vec3 b = targetColor.xyz;
    float dist = sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y) + (b.z - a.z) * (b.z - a.z));
    bool cond = dist < threshold * sqrt(3);
    // if color is within threshold, encode the pixel's position into red and green components
    // and use blue component as a marker that the pixel was in range
    // vertTexCoord is from 0 to 1, so after computing average, multiply by width and height to get screen position
    gl_FragColor = cond ? vec4(vertTexCoord.x, vertTexCoord.y, 1, 1) : vec4(0, 0, 0, 1);
}

【问题讨论】:

    标签: image-processing opengl-es glsl shader fragment-shader


    【解决方案1】:

    sqrt 仅支持浮点类型。它支持genType,但不支持genIType。但是,3 是整数。将 3 更改为 3.0:

    bool cond = dist &lt; threshold * sqrt(3);

    bool cond = dist < threshold * sqrt(3.0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-22
      • 2018-04-30
      • 2018-08-01
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多