The function section declares a general function, which unlike a GLSL function may be called in non-GLSL code, specifically in generators, other functions, and any expressions used in declarations. They may also be used the same way as GLSL functions.

Their syntax is the same as that of GLSL functions with several limitations:

  • No access to glsl sections or builtin shader constants
  • GLSL functions that involve textures or other OpenGL-specific constructs unavailable
  • Only basic GLSL variable types may be used, no structures or arrays
  • No output arguments (in, out, inout specifiers)
  • No switch statements


function float sqr(float x) {
    return x*x;

Such a function may then be used within declarations such as:

parameter float size = sqr(3.0) : range(1.0, sqr(6.0));
image MyImage = glsl(myShader, ivec2(sqr(size)));