WebGPU Shading Language
   HOME

TheInfoList



OR:

WebGPU Shading Language (WGSL) is a
high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific goals of a systematic operation; and are applied in a wide range of contexts, such as, for instance, in domains as widely varied as computer scienc ...
shading language 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". Offline rendering Shading languages used in of ...
with a syntax inspired by
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH) ...
. It was initially developed by the
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working together in ...
GPU for the Web Community Group to provide developers with a modern, safe, and portable shading language for the
WebGPU WebGPU API is a JavaScript, Rust, C++, and C API for cross-platform efficient graphics processing unit (GPU) access. Using a system's underlying Vulkan, Metal, or Direct3D 12 technologies, WebGPU allows for graphics processing, games, and mor ...
API An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
. WGSL is designed to be compiled to
SPIR-V Standard Portable Intermediate Representation (SPIR) is an intermediate language for General-purpose computing on graphics processing units, parallel computing and graphics by Khronos Group. It is used in multiple execution environments, including ...
or other intermediate representations, enabling execution across different graphics hardware while maintaining security and portability requirements essential for web applications.


Background

Traditional web graphics programming relied on
WebGL WebGL (short for Web Graphics Library) is a JavaScript Application programming interface, API for rendering interactive 2D and 3D graphics within any compatible web browser without the use of plug-in (computing), plug-ins. WebGL is fully integra ...
, which used GLSL ES for shader programming. However, as web applications became more sophisticated and demanded better performance, the need for a more modern graphics API became apparent. WebGPU was developed to address these needs, providing access to modern GPU features while maintaining the security and portability requirements of the web platform.


Shader types

WGSL supports multiple shader stages:


Vertex shaders

Process individual vertices, transforming positions and computing per-vertex data for rasterization.


Vertex shader example

/* Transforms incoming positions by an MVP matrix and passes per-vertex color through to the fragment stage. */ struct VertexInput ; struct VertexOutput ; @group(0) @binding(0) var mvp : mat4x4; @vertex fn main(v_in : VertexInput) -> VertexOutput


Fragment shaders

Execute for each fragment, computing final color values and depth information.


Fragment shader example

/* Receives interpolated color and writes it to the framebuffer. */ @fragment fn main(@location(0) color : vec3f) -> @location(0) vec4f


Compute shaders

Perform general-purpose parallel computations on the GPU, supporting various algorithms beyond traditional graphics rendering.


Compute shader example

/* Doubles every element in an input buffer and stores the result in an output buffer. */ struct Params ; @group(0) @binding(0) var in_data : array; @group(0) @binding(1) var out_data : array; @group(0) @binding(2) var params : Params; @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) gid : vec3)


See also

*
WebGPU WebGPU API is a JavaScript, Rust, C++, and C API for cross-platform efficient graphics processing unit (GPU) access. Using a system's underlying Vulkan, Metal, or Direct3D 12 technologies, WebGPU allows for graphics processing, games, and mor ...
, the graphics API that uses WGSL *
SPIR-V Standard Portable Intermediate Representation (SPIR) is an intermediate language for General-purpose computing on graphics processing units, parallel computing and graphics by Khronos Group. It is used in multiple execution environments, including ...
, intermediate shader representation *
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working together in ...
, the organization developing WebGPU and WGSL


Other shading languages

*
GLSL OpenGL Shading Language (GLSL) is a high-level shading language with a syntax based on the C programming language. It was created by the OpenGL ARB (OpenGL Architecture Review Board) to give developers more direct control of the graphics pipe ...
, shading language for OpenGL *
HLSL The High-Level Shader Language or High-Level Shading Language (HLSL) is a proprietary shading language developed by Microsoft for the Direct3D 9 API to augment the shader assembly language, and went on to become the required shading language ...
, Microsoft's shading language for Direct3D *
Metal Shading Language A metal () is a material that, when polished or fractured, shows a lustrous appearance, and conducts electricity and heat relatively well. These properties are all associated with having electrons available at the Fermi level, as against non ...
, Apple's shading language for Metal * Cg, NVIDIA's C-based shading language *
Open Shading Language Open Shading Language (OSL) is a shading language developed by Sony Pictures Imageworks, a Canadian visual effects and computer animation studio headquartered in Vancouver, British Columbia and Montreal, Quebec, with an additional office on the ...
, offline rendering shading language


References


External links


WebGPU Shading Language Specification
- Official W3C specification
WebGPU Specification
- The broader WebGPU API specification
WebGPU Working Group on GitHub
- Development repository {{DEFAULTSORT:WebGPU Shading Language Shading languages Web standards World Wide Web Consortium standards Computer graphics