glsl

The glsl section encloses GLSL code, from which shaders are composed. There are 4 types of GLSL sections: function, structure definition, variable declaration, and an unnamed block. Please see the OpenGL Reference Pages for information concerning GLSL syntax and usage.

GLSL function

A GLSL function can be defined following the glsl keyword. The name of the function can then be passed to various object initializers and modifiers. Functions can also be defined inside an unnamed block, but will then become invisible to Shadron, which means that they cannot be used outside GLSL code.

Example:

glsl float sqr(float x) {
    return x*x;
}

GLSL structure definition

A GLSL structure can be defined following the glsl keyword. Its name can then be used to specify the data type used for some objects. Currently, only basic data types (float, vec2, vec3, and vec4) are allowed in these structures. To use other data types, you may define the structure inside an unnamed block, but won't be able to use it outside GLSL code (e.g. as a fragment data type).

Example:

glsl struct MyVertex {
    vec3 coord;
    vec3 normal;
    vec2 textureCoord;
};

GLSL variable declaration

You may also declare a global variable following the glsl keyword. It will only be available in GLSL code and has no special meaning.

Example:

glsl float globalVar;

Unnamed GLSL block

To avoid having to type the glsl keyword in front of every declaration, you may place several inside a GLSL block. Any entities defined inside said block will be only available in GLSL code and cannot be passed as image generator functions, etc.

Example:

glsl {

    float globalVar;
    
    float getGlobalVar() {
        return globalVar;
    };
    
    void setGlobalVar(float value) {
        globalVar = value;
    }
  
}