Shaders
In short: A shader is a small program that runs on the graphics card and determines how geometry and pixels are displayed: position, color, light, shadows and surface effects.
In more detail: A graphics card is built to perform thousands of small calculations at the same time. Shaders are exactly these calculations: for each vertex or pixel the same program runs with different data. This is called parallel processing.
In Depth
Important kinds:
| Shader | Task |
|---|---|
| Vertex shader | Processes each vertex of a model: position in space, displacement, animation |
| Fragment/pixel shader | Computes the color of each pixel: texture, light, reflection, transparency |
| Geometry/tessellation shader | Creates or refines geometry (more triangles from few) |
| Compute shader | General calculations on the GPU (physics, AI, image filters) |
| Ray-tracing shader | Computing light rays for realistic lighting |
Sequence in the graphics pipeline: Model data → vertex shader → rasterization (triangles become pixels) → fragment shader → image.
Languages: GLSL (OpenGL), HLSL (DirectX, Unity), WGSL (WebGPU), Metal Shading Language (Apple), SPIR-V (Vulkan). Visual: Shader Graph (Unity), material editor (Unreal).
Example (GLSL fragment shader):
void main() {
// color from the texture, darkened depending on light
vec3 color = texture(tex, uv).rgb * max(dot(normal, lightDir), 0.0);
output = vec4(color, 1.0);
}Use:
- Lighting, shadows, water, smoke, skin, hair, fog.
- Post-processing: blur (bloom), color correction, anti-aliasing.
- Art styles: cel shading (comic look), pixel shaders, hologram effects.
- Not only games: films (render shaders), calculations, AI.
Cost: Complex shaders slow the frame rate. “Compiling shaders” at first start makes games load long (shader cache).
See also: Game engine, Unity, 3D modeling