Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL: My custom function isn't found

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);
}
like image 287
Alex Wayne Avatar asked Oct 12 '12 17:10

Alex Wayne


People also ask

Is OpenGL the same as GLSL?

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.

How do I add GLSL to Visual Studio?

Options of the extension can be found via the Visual Studio options dialog ( Tools -> Options -> glsl language integration ).

What is vec3 in GLSL?

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.

Does WebGL use GLSL?

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).


1 Answers

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.

like image 70
rgngl Avatar answered Nov 08 '22 04:11

rgngl