Search code examples
image-processingopengl-esglslshaderfragment-shader

no matching overloaded for function 'sqrt' found


I have this error with my glsl file

no matching overloaded for function 'sqrt' found

and this my following code

#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);
}

Solution

  • sqrt is only supports floating point types. It supports genType, but not genIType. However, 3 is an integer. Change 3 to 3.0:

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

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