GLSL shaders

Themaister edited this page Apr 30, 2013 · 1 revision


GLSL shader support exists to be compatible in case Cg shaders cannot be supported, which is the case for OpenGL ES, and EGL contexts (KMS mode in Linux for one).

Like Cg shaders, GLSL shaders represent a single pass, and requires a preset file to describe how multiple shaders are combined. The extension is .glsl. The internal format of the shaders are the same as modern XML shaders.

As GLSL shaders are normally placed in two different files (vertex, fragment), making it very impractical to select in a menu. This is worked around by using compiler defines in order to be equivalent to Cg shaders.

Example GLSL shader

varying vec2 tex_coord;
#if defined(VERTEX)
    attribute vec2 TexCoord;
    attribute vec2 VertexCoord;
    uniform mat4 MVPMatrix;
    void main()
        gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);
        tex_coord = TexCoord;
#elif defined(FRAGMENT)
    uniform sampler2D Texture;
    void main()
        gl_FragColor = texture2D(Texture, tex_coord);

GLSL shaders must be modern style, and using ruby prefix is discouraged.

Converting from Cg shaders

GLSL shaders are mostly considered a compatibility format. It is possible to compile Cg shaders into GLSL shaders automatically using our cg2glsl script found here. It can convert single shaders as well as batch conversion.

It relies on nVidia's cgc tool found in nvidia-cg-toolkit package.

GLSL preset

Like Cg shaders, there is a preset format. Instead of .cgp extension, .glslp extension is used. The format is exactly the same, just replace .cg shaders with .glsl. To convert a .cgp preset, rename to .glslp and replace all references to .cg shaders with .glsl.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.