shading language

{{short description|Graphics programming language}}

{{multiple issues|

{{lead too short|date=May 2014}}

{{more citations needed|date=August 2014}}

}}

A shading language is a graphics programming language adapted to programming shader effects. Shading languages usually consist of special data types like "vector", "matrix", "color" and "normal".{{cn|date=March 2025}}

Offline rendering

Shading languages used in offline rendering tend to be close to natural language, so that no special knowledge of programming is required. Offline rendering aims to produce maximum-quality images, at the cost of greater time and compute than real-time rendering.{{cn|date=March 2025}}

= RenderMan Shading Language =

The RenderMan Shading Language{{cite web |author= |year=1986–2012 |title=The RISpec |url=https://renderman.pixar.com/products/rispec/index.htm |url-status=dead |archiveurl=https://web.archive.org/web/20110725222410/https://renderman.pixar.com/products/rispec/index.htm |archivedate=25 July 2011 |accessdate=9 June 2012 |work=Pixar }} (RSL or SL, for short), defined in the RenderMan Interface Specification, is a common shading language for production-quality rendering. It is also one of the first shading languages ever implemented.{{cn|date=March 2025}}

It defines six major shader types:{{cn|date=March 2025}}

  • Light source shaders compute the color of light emitted from a point on a light source to a point on a target surface.
  • Surface shaders model the color and position of points on an object's surface, based on incoming light and the object's physical properties.
  • Displacement shaders manipulate surface geometry independent of color.
  • Deformation shaders transform the entire space. Only one RenderMan implementation, the AIR renderer by SiTex Graphics, implemented this shader type, supporting only a single linear transformation applied to the space.
  • Volume shaders manipulate the color of 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 like an image filter, except the imager shader operates on data prior to quantization. Such data have more dynamic range and color resolution than can be displayed on a typical output device.

= Houdini VEX Shading Language =

Houdini VEX (Vector Expressions) shading language (often abbreviated to "VEX") is closely modeled after RenderMan. However, its integration into a complete 3D package means that the shader writer can access the information inside the shader, a feature that is not usually available in a rendering context. The language differences between RSL and VEX are mainly syntactic, in addition to differences regarding the names of several shadeop names.{{cite web|title=Houdini|url=http://www.vislab.usyd.edu.au/sidefx/|work=Side FX|publisher=Side Effects Software Inc|accessdate=9 June 2012|author=|archiveurl=https://web.archive.org/web/20080722204951/http://oldsite.vislab.usyd.edu.au/resources/guide/houdini/|archivedate=22 July 2008}}

= Gelato Shading Language =

Gelato's{{cite web|title=Home|url=http://www.nvidia.com/page/gz_home.html|work=NVIDIA Gelato Zone|publisher=NVIDIA Corporation|accessdate=9 June 2012|author=|archiveurl=https://web.archive.org/web/20060426231931/http://film.nvidia.com/page/gelato.html |archivedate=26 April 2006 |year=2003–2008}} 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.{{cn|date=March 2025}}

= Open Shading Language =

Open Shading Language (OSL) was developed by Sony Pictures Imageworks for use in its Autodesk 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.{{cn|date=March 2025}}

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. They deliver more control and richer content with less overhead.{{cn|date=March 2025}}

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 (see also: GPGPU).{{cn|date=March 2025}}

Historically, a few such languages dominated the market;{{cn|date=March 2025}} they are described 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.{{cn|date=March 2025}}

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.{{cn|date=March 2025}}

= OpenGL shading language =

Also known as GLSL or glslang, this standardized{{cite web|title=OpenGL Shading Language|url=http://www.opengl.org/documentation/glsl/|work=OpenGL|publisher=The Khronos Group|accessdate=9 June 2012|author=|year=1997–2012}} shading language is meant to be used with OpenGL. {{cn|date=March 2025}}

The language unifies vertex and fragment processing in a single instruction set, allowing conditional loops and branches. GLSL was preceded by the ARB assembly language.{{cn|date=March 2025}}

= Cg programming language =

The Cg language, developed by Nvidia,{{cite web|title=Cg Toolkit|url=http://developer.nvidia.com/cg-toolkit|work=NVIDIA Developer Zone|publisher=NVIDIA Corporation|accessdate=9 June 2012|author=|year=2012}} was designed for easy and efficient production pipeline integration. It features API independence and comes with many free tools{{ref|fxcomp}} to improve asset management. Development of Cg was stopped in 2012, and the language is now deprecated.{{cn|date=March 2025}}

= 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. It is a direct representation of the intermediate shader bytecode which is passed to the graphics driver for execution.{{cn|date=March 2025}}

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.{{Cite web|url=https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm|title=Asm Shader Reference|date=10 December 2019|website=learn.microsoft.com}}

= DirectX High-Level Shader Language =

The High-Level Shading Language (HLSL) 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.{{cn|date=March 2025}}

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.{{cn|date=March 2025}}

= Adobe Pixel Bender and Adobe Graphics Assembly Language =

Adobe Systems 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 (AGAL), which offers full 3D acceleration support.{{cite book|author=Joseph Labrecque|title=What's New in Adobe AIR 3|url=https://archive.org/details/whatsnewadobeair03labr_317|url-access=limited|year=2011|publisher=O'Reilly Media, Inc.|isbn=978-1-4493-1108-7|pages=[https://archive.org/details/whatsnewadobeair03labr_317/page/n30 17]–26}}{{cite book|editor=Eric Lengyel|title=Game Engine Gems 2|year=2011|publisher=CRC Press|isbn=978-1-56881-437-7|chapter=3D in a Web Browser|author=Remi Arnaud|pages=207–212}} GPU acceleration for Pixel Bender was removed in Flash 11.8.{{cite web|url=http://wiki.scratch.mit.edu/wiki/Stage3D|accessdate=5 August 2014|title=Stage3D|publisher=scratch.mit.edu}}{{Cite web|url=https://bugbase.adobe.com/index.cfm?event=bug&id=3591185|archiveurl=https://web.archive.org/web/20140422031641/https://bugbase.adobe.com/index.cfm?event=bug&id=3591185|url-status=dead|title=Adobe Flash Player 11.8 - Bug 3591185|archivedate=22 April 2014}}

AGAL is a low-level but platform-independent shading language, which can be compiled, for example, {{citation needed span|to the ARB assembly language|date=August 2014}} or GLSL.

= PlayStation Shader Language =

Sony announced PlayStation Shader Language (PSSL) as a shading language similar to Cg/HLSL, but specific to the PlayStation 4. PSSL is said to be largely compatible with the HLSL shader language from DirectX 12, but with additional features for the PS4 and PS5 platforms.{{cite web |author1=Richard Stenson |author2=Chris Ho|title=PlayStation Shading Language for PS4 |url=https://www.gdcvault.com/play/1019252/PlayStation-Shading-Language-for |website=GDC Europe 2013}}

=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 has its own shading language called Metal Shading Language (MSL), which is based on C++14 and implemented using clang and LLVM. MSL unifies vertex, fragment and compute processing.{{cite web|url=https://developer.apple.com/library/prerelease/ios/documentation/Metal/Reference/MetalShadingLanguageGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014364|title=Metal Shading Language Specification|version=3.2|date=6 June 2024|publisher=Apple}}

= WebGPU Shading Language =

WebGPU Shading Language (WGSL) is the shader language for WebGPU. That is, an application using the WebGPU API uses WGSL to express the programs, known as shaders, that run on the GPU.{{cite web | url=https://www.w3.org/TR/WGSL | title=WebGPU Shading Language|publisher=W3C|date=22 March 2025|access-date= }}

Translation

To port shaders from one shading language to another, a few approaches are used:{{cite web |author=Aras Pranckevičius|title=Cross Platform Shaders in 2014|publisher= Aras Pranckevičius |date=28 March 2014 |url=http://aras-p.info/blog/2014/03/28/cross-platform-shaders-in-2014/ |language=en-us}}

  • Define a common interface. For example, Cg/HLSL, GLSL, and MSL all implement C preprocessor 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. For example, DirectX bytecode can be partially converted to GLSL via HLSLcc, and several tools for converting GLSL to HLSL such as ANGLE and HLSL2GLSL exist.
  • Define an 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.{{cite web |title=SPIR-V Toolchain |url=https://vulkan.lunarg.com/doc/sdk/1.2.135.0/windows/spirv_toolchain.html |website=LunarXchange|url-status=dead|archive-url=https://web.archive.org/web/20220709080846/https://vulkan.lunarg.com/doc/sdk/1.2.135.0/windows/spirv_toolchain.html|archive-date=9 July 2022}}

Notes

  1. {{note|oldVtx}} Previous vertex shading languages (in no particular order) for OpenGL include [http://oss.sgi.com/projects/ogl-sample/registry/EXT/vertex_shader.txt EXT_vertex_shader], [http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_program.txt NV_vertex_program], the aforementioned [http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt ARB_vertex_program], [http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_program2.txt NV_vertex_program2] and [http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_program3.txt NV_vertex_program3].
  2. {{note|oldFrag}} For fragment shading [https://web.archive.org/web/20060324081236/http://developer.nvidia.com/object/nvparse.html nvparse] is possibly the first shading language featuring high-level abstraction based on [http://oss.sgi.com/projects/ogl-sample/registry/NV/register_combiners.txt NV_register_combiners], [http://oss.sgi.com/projects/ogl-sample/registry/NV/register_combiners2.txt NV_register_combiners2] for pixel math and [http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_shader.txt NV_texture_shader], [http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_shader2.txt NV_texture_shader2] and [http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_shader3.txt NV_texture_shader3] for texture lookups. [http://oss.sgi.com/projects/ogl-sample/registry/ATI/fragment_shader.txt ATI_fragment_shader] did not even provide a "string oriented" parsing facility (although it has been later added by [http://oss.sgi.com/projects/ogl-sample/registry/ATI/text_fragment_shader.txt ATI_text_fragment_shader]). [http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_program.txt ARB_fragment_program], has been very successful. [http://oss.sgi.com/projects/ogl-sample/registry/NV/fragment_program.txt NV_fragment_program] and [http://oss.sgi.com/projects/ogl-sample/registry/NV/fragment_program2.txt NV_fragment_program2] are actually similar although the latter provides much more advanced functionality in respect to others.
  3. {{note|fxcomp}} [http://developer.nvidia.com/object/fx_composer_home.html Fx composer from NVIDIA home page]
  4. Rudy Cortes and Saty Raghavachary: The RenderMan Shading Language Guide, Course Technology PTR, 1 edition (December 27, 2007), {{ISBN|1-59863-286-8}}

References