Introduction
GLSL, the OpenGL Shading Language, is the Khronos Group’s C-like language for shaders, the small programs that run on the graphics card. It is used by OpenGL, OpenGL ES and WebGL, which compile it in the graphics driver while the program runs, and by Vulkan, which takes it compiled ahead of time to SPIR-V.
There is no single official extension. Files are named .glsl, or after
the shader stage: .vert for vertex shaders, .frag for
fragment shaders, and .geom, .comp, .tesc and
.tese for geometry, compute and tessellation shaders, the names the glslang
compiler recognises.
Structure
A GLSL file is plain text. It starts with a #version line naming the
language version, such as 450 for desktop OpenGL 4.5 or
300 es for OpenGL ES 3.0. Then come declarations of the shader’s inputs,
outputs and uniforms (values set by the program), often with layout
qualifiers giving their locations, then functions. Execution starts at
void main(). The language has built-in vector and matrix types such as
vec4 and mat4.
#version 450
layout(location = 0) in vec3 colour;
layout(location = 0) out vec4 fragColour;
void main() {
fragColour = vec4(colour, 1.0);
}
Links
Software
- glslang, the reference compiler and validator (Windows, macOS, Linux)
- Shaderc, whose
glslccompiles GLSL to SPIR-V (Windows, macOS, Linux) - Vulkan SDK, which bundles both (Windows, macOS, Linux)
- RenderDoc, which shows and edits the shaders of a running program (Windows, Linux)
- Shadertoy, for writing fragment shaders in the browser (web)
Reference
- OpenGL Registry, Khronos Group, with the GLSL specifications