GLSL: my custom function not found

So, I have this fragment shader that works fine until I reworked some logic into a separate function. I want to be able to name it several times to overlap different versions of the effect on each other.

However, as soon as I created this custom function, the shader starts throwing an error:

ERROR: 0:33: 'grid' : no matching overloaded function found 

Which is weirder, because it seems to compile it as a function. If I remove return from grid() , I will also get this error:

 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); } 
+6
source share
1 answer

You either need to put the grid function before the main one or forward declare it the same way as in c.

For instance:

 float grid(float size); 

before the main method.

+16
source

Source: https://habr.com/ru/post/927591/


All Articles