Search code examples
glslwebglglsles

Error compiling shader '[object WebGLShader]':ERROR: 0:82: 'sqrt' : no matching overloaded function found


I am doing a calculation in GLSL (Shading Language) which is as follows

int N = 3;
  float sigma_H = 5
 for(int i = 0 ;i < 3 ; i++){
float sigma_H_i = sigma_H * sqrt(3) * pow(2,(N - (i + 1))) / sqrt(pow(4,N) - 1.0);
}

The Error I am getting is

webgl-utils.js:66 *** Error compiling shader '[object WebGLShader]':ERROR: 0:82: 'sqrt' : no matching overloaded function found 
ERROR: 0:82: 'pow' : no matching overloaded function found 
ERROR: 0:82: 'pow' : no matching overloaded function found 

WARNING: 0:82: 'sqrt' : operation result is undefined for the values passed in 
ERROR: 0:104: '' : syntax error

I knew the error is in the following block of code because as soon as I remove following line it compile correctly

 float sigma_H_i = sigma_H * sqrt(3) * pow(2,(N - (i + 1))) / sqrt(pow(4,N) - 1.0);

Can Any one please tell me why am I getting this error that there is no pow function although I knew that there is 'pow()' function in GLSL fromOpenGL Shading Language (GLSL) Quick Reference Guide

enter image description here

I am using Google Chrome Browser


Solution

  • Well, your code is invalid. According to the GLSL ES spec:

    When the built-in functions are specified below, where the input arguments (and corresponding output) can be float, vec2, vec3, or vec4, genType is used as the argument.

    You are calling it with an int, and GLSL does not do any implicit conversions (in contrast to C), so the correct syntax would have to be something like

    float sigma_H_i = sigma_H * sqrt(3.0) * pow(2.0,(float(N - (i + 1)))) / sqrt(pow(4.0,float(N)) - 1.0);