-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
GLSL shaders
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.
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);
}
#endif
GLSL shaders must be modern style, and using ruby
prefix is discouraged.
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.
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.