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);
}
The short version is: OpenGL is an API for rendering graphics, while GLSL (which stands for GL shading language) is a language that gives programmers the ability to modify pipeline shaders. To put it another way, GLSL is a (small) part of the overall OpenGL framework.
Options of the extension can be found via the Visual Studio options dialog ( Tools -> Options -> glsl language integration ).
vec3 is a floating point vector with three components. It can be initialized by: Providing a scalar value for each component. Providing one scalar value. This value is used for all components.
WebGL require a shader program for the vertex and fragment manipulation sections of the graphics pipeline. A shader program are written in GLSL (Graphics Library Shader Language).
You either have to put the grid function before the main or forward declare it as you would in c.
Such as:
float grid(float size);
before the main method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With