Other meanings of Shader
Computer graphics
A shader is a computer program used in 3D computer graphics to calculate rendering effects. It runs on a graphics processing unit (GPU), or sometimes another processor, and determines how vertices, surfaces, pixels, or other data are transformed into an image.
A shader calculates one stage of a graphics pipeline, turning geometric and material data into screen pixels. Traditional real-time pipelines divided this work into fixed stages, but programmable shaders allow developers to define many of the calculations themselves.1 A vertex shader commonly transforms object coordinates into positions on the screen and passes attributes such as normals or texture coordinates onward. A fragment or pixel shader evaluates samples that may become visible pixels, combining textures, lighting, shadows, reflections, and transparency.
Modern APIs also expose specialized stages. A geometry shader can create or discard primitives, while tessellation shaders subdivide surfaces before rasterization. Compute shaders use the GPU’s parallel hardware for general calculations without necessarily producing triangles, including image processing, particle simulation, and culling.
Shader languages express highly parallel programs under the rules of a graphics API. OpenGL commonly uses the OpenGL Shading Language (GLSL), Direct3D uses High-Level Shader Language (HLSL), and Vulkan applications can use languages that compile to the standardized SPIR-V intermediate representation.2 WebGPU defines a portable shading language called WGSL for browser and native implementations.3
A shader is normally compiled or translated before execution. The resulting code is specialized for a GPU architecture, pipeline state, and resource layout. Developers therefore manage inputs such as uniform values, buffers, textures, and samplers, while the API validates how those resources are connected to each stage. Compilation errors, precision differences, unsupported features, and divergent control flow can all affect portability and performance.
Shaders define much of a rendered object’s visible appearance. A surface shader may implement a physically based material model, using values such as base color, roughness, metallic response, and a normal map to estimate how light is reflected. More specialized programs can produce toon shading, subsurface-like effects, water, foliage, volumetric fog, motion blur, or screen-space reflections.
Lighting calculations may be performed directly in a shader or supplied by a larger rendering framework. Techniques such as shadow mapping render depth from a light’s viewpoint, then compare that depth during later shading. Deferred shading separates geometric information from lighting, storing attributes in intermediate buffers before evaluating many lights. Ray-tracing pipelines add programmable ray-generation, intersection, any-hit, closest-hit, and miss shaders to calculate paths through a scene.4
Shaders are also used outside the familiar vertex-and-pixel pair. Compute shaders can accelerate non-visual workloads such as histogram construction, fluid simulation, neural-network operations, and spatial searches, although synchronization and memory access remain important constraints. GPU vendors and APIs may expose subgroup or wave operations that let invocations exchange data efficiently, but these features can reduce portability.
Shader execution is not simply “one program per pixel.” GPUs usually process groups of invocations together, so branches whose members take different paths can reduce efficiency. Precision qualifiers, derivative instructions, early depth tests, and texture filtering can likewise change results in subtle ways. Security is another edge case: browsers and modern APIs restrict shader capabilities and resource access because untrusted shader code must not read arbitrary host memory. Portable shader development consequently involves both mathematical design and careful API-specific testing.
Shader terminology varies among graphics APIs: a fragment shader in OpenGL corresponds broadly to a pixel shader in Direct3D, although the execution and interface rules are API-specific.
Help improve the encyclopedia. Reports go straight to the site manager.