So I have this fragment shader, which was working great until I refactored some logic out into a separate function. I want to be able to call it multiple times to layer different versions of the effect on top of each other.
However, as soon as I created this custom function, the shader starts throwing the error:
ERROR: 0:33: 'grid' : no matching overloaded function found
Which is wierd, because it appears to be compiling it as function. If I remove the return from grid() I get this error too:
ERROR: 0:36: '' : function does not return a value: grid
So what am I missing here about declaring functions?
Full shader here:
uniform float brightness;
uniform float shiftX;
uniform float shiftY;
uniform vec4 color;
varying vec3 vPos;
void main() {
gl_FragColor = vec4( grid(200.0), 0.0, 0.0, 1.0 );
}
float grid(float size) {
float x = pow(abs(0.5 - mod(vPos.x + shiftX, 200.0) / 200.0), 4.0);
float y = pow(abs(0.5 - mod(vPos.y + shiftY, 200.0) / 200.0), 4.0);
return (x+y) * 5.0 * pow(brightness, 2.0);
}
You either have to put the grid function before the main or forward declare it as you would in c.
Such as:
before the main method.