Shading language
A shading language is a graphics programming language adapted to programming shader effects. Such language forms usually consist of special data types, like "vector", "matrix", "color" and "normal". Due to the variety of target markets for 3D computer graphics, different shading languages have been developed.
Offline rendering
Shading languages used in offline rendering produce maximum image quality. Material properties are totally abstracted, little programming skill and no hardware knowledge is required. These kind of shaders are often developed by artists to get the right "look", just as texture mapping, lighting and other facets of their work.Processing such shaders is time-consuming. The computational power required can be expensive because of their ability to produce photorealistic results. Most of the time, production rendering is run on large computer clusters.
RenderMan Shading Language
The RenderMan Shading Language, which is defined in the RenderMan Interface Specification is the most common shading language for production-quality rendering. It is also one of the first shading languages ever implemented.The language defines six major shader types:
- Light source shaders compute the color of the light emitted from a point on the light source towards a point on the target surface.
- Surface shaders model the optical properties of an illuminated object. They output the final color and position of the point by considering the incoming light and the object's physical properties.
- Displacement shaders manipulate surface geometry independent of color.
- Deformation shaders transform the entire space of a geometry. Only one RenderMan implementation, the AIR renderer, implemented this shader type, supporting only a single linear transformation applied to the space.
- Volume shaders manipulate the color of a light as it passes through a volume. They create effects such as fog.
- Imager shaders describe a color transformation to final pixel values. This is much like an image filter, however the imager shader operates on data prior to quantization. Such data has a greater dynamic range and color resolution than can be displayed on a typical output device.
Houdini VEX Shading Language
Gelato Shading Language
's shading language, like [|Houdini's VEX], is closely modeled after RenderMan. The differences between Gelato Shading Language and RSL are mainly syntactical — Gelato uses semicolons instead of commas to separate arguments in function definitions and a few shadeops have different names and parameters.Open Shading Language
was developed by Sony Pictures Imageworks for use in its Arnold Renderer. It is also used by Blender's Cycles render engine. OSL's surface and volume shaders define how surfaces or volumes scatter light in a way that allows for importance sampling; thus, it is well suited for physically-based renderers that support ray tracing and global illumination.Real-time rendering
Shading languages for real-time rendering are now widespread. They provide both higher hardware abstraction and a more flexible programming model than previous paradigms which hardcoded transformation and shading equations. This gives the programmer greater control over the rendering process and delivers richer content at lower overhead.Shaders that are designed to be executed directly on the GPU became useful for high throughput general processing because of their stream programming model; this led to the development of compute shaders running on similar hardware.
Historically, only few such languages were successful in both establishing themselves and maintaining strong market position; a short description of those languages follows below.
ARB assembly language
The OpenGL Architecture Review Board established the ARB assembly language in 2002 as a standard low-level instruction set for programmable graphics processors.High-level OpenGL shading languages often compile to ARB assembly for loading and execution. Unlike high-level shading languages, ARB assembly does not support control flow or branching. However, it continues to be used when cross-GPU portability is required.
OpenGL shading language
Also known as GLSL or glslang, this standardized shading language is meant to be used with OpenGL.The language unifies vertex and fragment processing in a single instruction set, allowing conditional loops and branches. Historically, GLSL was preceded by the ARB assembly language.
Cg programming language
The programming language Cg, developed by NVIDIA, was designed for easy and efficient production pipeline integration. The language features API independence and comes with a large variety of free tools to improve asset management. Development of Cg was stopped in 2012 and the language is now deprecated.DirectX Shader Assembly Language
The shader assembly language in Direct3D 8 and 9 is the main programming language for vertex and pixel shaders in Shader Model 1.0/1.1, 2.0, and 3.0. The shader assembly language is a direct representation of the intermediate shader bytecode which is passed to the graphics driver for execution.The shader assembly language cannot be directly used to program unified Shader Model 4.0, 4.1, 5.0, and 5.1, although it retains its function as a representation of the intermediate bytecode for debug purposes.
DirectX High-Level Shader Language
The High-Level Shading Language is a C-style shader language for DirectX 9 and higher and Xbox game consoles. It is related to Nvidia's Cg but is only supported by DirectX and Xbox. HLSL programs are compiled into bytecode equivalent of DirectX shader assembly language.HLSL was introduced as an optional alternative to the shader assembly language in Direct3D 9, but became a requirement in Direct3d 10 and higher, where the shader assembly language is deprecated.
Adobe Pixel Bender and Adobe Graphics Assembly Language
added Pixel Bender as part of the Adobe Flash 10 API. Pixel Bender could only process pixel but not 3D-vertex data. Flash 11 introduced an entirely new 3D API called Stage3D, which uses its own shading language called Adobe Graphics Assembly Language, which offers full 3D acceleration support. GPU acceleration for Pixel Bender was removed in Flash 11.8.AGAL is a low-level but platform-independent shading language, which can be compiled, for example, or GLSL.
PlayStation Shader Language
announced PSSL as a platform-specific shading language similar to Cg/HLSL for the PlayStation 4. It is said to be largely compatible with HLSL shaders on PC, but with additional features for the PS4 platform.Metal Shading Language
Apple has created a low-level graphics API called Metal, which runs on most Macs made since 2012, iPhones since the 5S, and iPads since the iPad Air. Metal introduces its own shading language called Metal Shading Language, which is based on C++14 and implemented using clang and LLVM. MSL unifies vertex, fragment and compute processing.Translation
As more and more graphics APIs become available, developers face the problem of porting shaders from one shading languages to another. A few approaches are used:- Manual switching using C preprocessor statements. Cg/HLSL, GLSL, and MSL all implement CPP macros, so it is possible to wrap all the different operations into a common interface. Valve's Source 2 and NVIDIA's FXAA 3.11 do this.
- Translate one language to the other. DirectX bytecode partially can be converted to GLSL via HLSLcc, and several tools for converting GLSL to HLSL such as ANGLE and HLSL2GLSL exist.
- Define a different intermediate language. SPIR-V is designed partially for this purpose. It can be generated from HLSL or GLSL, and be decompiled into HLSL, GLSL, or MSL.