The OpenGL® shading language (GLSL) is a computer programming language designed specifically to manipulate and control three-dimensional (3D) graphics during the rendering process directly within the graphical processing unit (GPU) of a graphics card using OpenGL® libraries. In essence, OpenGL® shading language gives programmers direct access to 3D geometry and rendering at the lowest level possible without actually having to write assembly language routines to interface with GPU hardware. Through the use of the OpenGL® shading language, effects such as procedurally generated textures and geometry can be implemented and optimized directly within the GPU, speeding up the rendering process. It also allows more complex functions, such as animation or special effects, to be efficiently implemented without the overhead of higher-level code. The shading language is compiled by the GPU into executable code, meaning specific implementations and compilers can be designed for individual graphics cards, increasing the performance gains from using the different shaders.
For all practical purposes, the OpenGL® shading language is a fully implemented programming language that mimics the syntax of the C programming language in nearly all ways, with the exception of pointer-type variables and some preprocessor directives. User-defined functions, variables and logical branching and looping statements are all supported, allowing fully realized programs to be written using just the shader language, and providing a level of abstraction that is portable across different operating systems and hardware configurations. Once a shader program is completed, it is passed to the GPU, where it is compiled and executed as needed during the rendering process.
A program written in the OpenGL® shading language is ultimately passed to the GPU, where it can be compiled by hardware or drivers produced by the manufacturer of the graphics card. This means certain statements used inside the language can have their actual compiled bytecode optimized to work efficiently with the specific hardware features of a specific graphics card. This increases the speed of execution and can extend the basic functionality to include special rendering options and effects that could be unique to a single graphics card.
There are three types of shaders that the OpenGL® shading language can be used to write. The first is known as a vertex shader and is designed to perform complex operations on individual vertices, such as translating, scaling or texturing a point in space. The second is a geometry shader and can be used to add, remove or otherwise manipulate polygons before they are eventually rasterized. Fragment shaders, also called pixel shaders, can be written to perform operations on points in the 3D scene as they are translated into a flat two-dimensional (2D) image for display on a screen, such as lighting effects or distortions.