未找到函数 'sqrt' 的匹配重载

no matching overloaded for function 'sqrt' found

我的 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);
}

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

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

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