Every pixel of a modern game is coloured by a shader. A shader is a small program that runs on the graphics card, usually millions of times per frame, once for each vertex or pixel it touches. Materials, lighting, water, fog, outlines and most visual effects are shaders underneath.
Shader work sits between art and programming. Technical artists and graphics programmers write shaders so that artists can get a look, and so that the look runs fast enough.
What a shader does
The GPU draws a frame in stages, and shaders plug into several of them. The two that matter most for day-to-day game work are:
- Vertex shaders. Run once per vertex. They place geometry on screen and can move it, for example to make grass sway, water ripple or a flag wave.
- Pixel shaders, also called fragment shaders. Run once per pixel covered by a surface. They decide its final colour from textures, light and other inputs.
Other stages exist, such as compute shaders for general calculations on the GPU, which power large particle systems and some post-processing. The Wikipedia article on shaders gives a short overview of the types.
Code or nodes
Shaders can be written as code or built visually.
| Approach | Where it is used | Strengths | Limits |
|---|---|---|---|
| Node graphs | Unreal Material Editor, Unity Shader Graph | Fast to iterate, artists can work alone | Harder to optimise in detail, large graphs get messy |
| Shader code | HLSL, GLSL, engine-specific languages | Full control, reusable functions, better for complex techniques | Needs programming skills, slower to experiment |
HLSL is the shading language of DirectX and is widely used across engines. GLSL is used with OpenGL and Vulkan. In practice, most teams mix both approaches: node graphs for most materials, with custom code nodes for anything unusual.
Common shader jobs in games
- Surface materials. Combining PBR textures into metal, skin, cloth and stone. See textures and materials.
- Stylised lighting. Toon ramps, painted shadows and outlines for non-realistic art.
- Effects. Dissolves, energy, force fields, holograms and the materials used by particles. See Unreal VFX and shaders and Unity VFX and shaders.
- Environment. Water, foliage wind, snow coverage, wetness and terrain blending.
- Post-processing. Colour grading, bloom, outlines and screen-space effects applied to the whole frame.
- Gameplay feedback. Hit flashes, highlights on interactive objects and damage overlays.
How a shader is built
- Define the look. Start from concept art or a reference and agree on what must be true: does it react to light, does it move, does it need transparency?
- Prototype quickly. A node graph is often the fastest way to find the effect.
- Expose parameters. Colours, speeds and strengths that artists can change without editing the shader.
- Make it work everywhere. Check the shader under different lights, from different angles and on every target platform.
- Optimise. Reduce texture samples, move maths from the pixel shader to the vertex shader where possible, and remove features nobody uses.
- Document it. A short note on what each parameter does saves hours for the next artist.
For learning the basics of pixel shaders, The Book of Shaders remains a well-known free introduction.
Measure the cost
A shader runs for every pixel it covers, so small inefficiencies multiply. The main costs are:
- Texture samples. Each lookup costs memory bandwidth.
- Instruction count. Complex maths on every pixel adds up, especially at high resolutions.
- Transparency and overdraw. Transparent surfaces are shaded once per layer.
- Shader variants. Every combination of features can compile into a separate shader. Too many variants slow builds and increase memory and loading stutters.
Engines provide views and profilers to see shader cost per pixel. Always test on the weakest target hardware. Performance optimization covers the wider process.
Common mistakes
- One giant master shader. Every feature switch adds variants. Split shaders by purpose.
- Pixel maths that could be per vertex. Values that change slowly across a surface can often be computed per vertex.
- Ignoring mobile limits. Precision, texture formats and features differ on phones.
- No fallback. If a feature is unsupported on a platform, the shader needs a simpler path.
- Hard-coded values. Artists need parameters, not code edits, to tune the look.
FAQ
What is the difference between a shader and a material?
A shader is the program. A material is an instance of it with specific textures and parameter values. One shader can drive many materials.
Do I need to learn maths to write shaders?
Some. Vectors, dot products, interpolation and basic trigonometry cover most game shaders.
Which language should I learn first?
HLSL is a practical choice for game work, because it is used in Unreal and Unity code paths. Node editors in both engines are a good way to start.
What are compute shaders used for in games?
General calculations on the GPU, such as particle simulation, culling, terrain generation and some lighting techniques.