glsl

Declarations beginning with the glsl keyword enclose GLSL-specific code. Elements declared in this way will be inaccessible in most non-GLSL contexts. Please refer to OpenGL documentation for information about the GLSL language and its syntax.

Unnamed GLSL block

Portions of code directly ported from a GLSL shader can be enclosed in an anonymous GLSL block. Contents of such a block won't be parsed by Shadron and will be directly copied to every shader. Entities defined inside the block won't be available outside shaders. This may however cause unexpected conflicts and errors.

Example:

glsl {

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

GLSL variable declaration

You may also declare a shader variable following the glsl keyword. It will only be available in GLSL code and has no special meaning. Keep in mind that the variable is recreated every time a shader is evaluated and its value won't be remembered. For a persistent global variable, see var.

Example:

glsl float shaderVar;

GLSL function

A function definition may follow the glsl keyword. In the current version of Shadron, this variant is mostly deprecated in favor of general function declarations.

Example:

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

GLSL structure definition

A GLSL structure can be defined following the glsl keyword. In the current version of Shadron, this variant is mostly deprecated in favor of general structure declarations.

Example:

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