Vertex and fragment shaders
Two kinds of shader work together to draw an image [1]:
| Vertex shader | Fragment shader | |
|---|---|---|
| Runs | once per vertex | once per pixel |
| Job | compute the position on screen | compute the colour |
Because the GPU runs huge numbers of these calculations in parallel, it takes a lot of work off the CPU [1].
Languages
- GLSL (OpenGL Shading Language) for WebGL: strongly typed, C-like, with plenty of vector and matrix maths [1].
- WGSL (WebGPU Shading Language) for WebGPU [2][3].
Why shaders matter for configurators
Every material is ultimately a shader. Libraries such as three.js generate them automatically from material settings. Two practical consequences follow:
- Per-pixel cost: elaborate materials with clearcoat, transmission or sheen need more processing per pixel [4]. On large high-resolution screens this adds up.
- Compile time: shaders are compiled for the GPU when first used. Many different materials can noticeably lengthen the start of a 3D view.
Example: cut-away view
A cut-away view discards every pixel beyond a clipping plane while drawing. three.js offers such clipping planes as a setting on the renderer and on materials [5], with no custom shader needed. That is how the cut-away view in the planetary gearhead (example configurator, fictional product) works.
Custom shaders
For special effects such as cut faces, highlights or stylised rendering, developers write their own shaders or extend existing ones. That is powerful but makes a project harder to maintain. We only use custom shaders when standard materials cannot reach the goal.
The pillar page 3D configurator shows where such technical choices fit in a project.